Search code examples
javascripthtmlaudiotogglebuttonmute

mute and unmute button toggle html5 audio


I've understood how to mute an <audio> sound object by putting this code :

<a href="#" onclick="document.getElementById('ambiance').muted = true; return false">
    mute sound
</a>

Now I'm searching how to mute/unmute my sound using the same button with the option to toggle it ?

Can anyone give me directions?


Solution

  • var audioElm = document.getElementById('ambiance'); audioElm.muted = !audioElm.muted;