jQuery HTML Element How to - Mute the audio








Question

We would like to know how to mute the audio.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-compat-git.js'></script>
<script type='text/javascript'>
$(function(){<!--from   ww  w .j  a v  a  2 s.  c om-->
    jQuery('#sound').click(function () {
        jQuery('audio').prop("muted", true);
    });
});
</script>
</head>
<body>
  <audio id="audio" autoplay="autoplay">
    <source src="your audio file" />
  </audio>
  <a href="#noscroll" id="sound">toggle sound</a>
</body>
</html>

The code above is rendered as follows: