1

Right now on my site, (http://www.thehistoryofhiphop.net), I am trying to make my mute button functional. I want it to mute the background music that I have playing. How can I make it mute on click of the image? Here's my html for the music:

<embed src="no_joke.mp3" loop="true" autostart="true" hidden="true" id="music"/>     

1 Answers1

1

embed tag has no muted attribute, so use audio tag.

and take this code:

<script>
function toggleSound() {
  var elements = document.getElementsByTagName('audio');
  for(var e = 0; e < elements.length; elements[e].muted = !elements[e].muted, e++);
}
</script>

<button onclick="toggleSound()">TOGGLE SOUND</button>

<audio 
       src="http://www.thehistoryofhiphop.net/no_joke.mp3" 
       preload="auto" 
       loop="true" 
       autoplay="true" 
       id="music">
num8er
  • 18,604
  • 3
  • 43
  • 57