Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
98
rated 0 times [  100] [ 2]  / answers: 1 / hits: 60219  / 13 Years ago, wed, june 22, 2011, 12:00:00

What's the best way to mute a HTML5 audio element? I don't want the browser's custom controls, so I've been looking at the javascript instead. Unfortunately it just doesn't seem to work for me :( I'm undoubtedly doing something very wrong.



    <audio id=background_audio autoplay=autoplay>
<source src=static/audio/clip.ogg type=audio/ogg />
<source src=static/audio/clip.mp3 type=audio/mpeg />
</audio>

<a href=# onclick=document._video.muted=true; return false>mute sound</a>


Still getting my head around this. Thanks!


More From » html

 Answers
22

This should work:



document.getElementById('background_audio').muted = true;


Demo: http://jsfiddle.net/mattball/sVwXH/ (no jQuery)


[#91562] Tuesday, June 21, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pierce

Total Points: 315
Total Questions: 103
Total Answers: 89

Location: Svalbard and Jan Mayen
Member since Mon, Jun 7, 2021
3 Years ago
;