Toggle Mute Javascript Function with Jquery Toggle
<p>Hi All I am trying to write both an if/else statement along with toggling an image. Basically my goal is to toggle an image (in this case with an id of soundonoff). However I can't seem to figure out where I am going wrong. The issue is the toggle works, but the detect of whether its muted or not does not work. (In my full code for example I have it switch <code>innerHTML</code> of various audio/video files, this is where <code>document.getElementsByName('mymedia')[0]</code> comes in. Any help would be tremendously appreciated I have spent about 4 hours working on this and can't seem to figure it out.</p>

<p>I should add that I do not know where to add an eventlistener for <code>detectmute()</code>, I tried to add it to my video, and to the button soundonoff but neither got working yet.</p>

<p>Here is my code: </p>

<pre><code>function detectmute(){
if(document.getElementById('soundonoff').src == 'images/icons/soundoff.png'){
document.getElementsByName('mymedia')[0].muted = true;
}
else if(document.getElementById('soundonoff').src == 'images/icons/soundon.png'){
document.getElementsByName('mymedia')[0].muted = false;
}
$("#soundonoff").toggle(function(){
this.src = "images/icons/soundoff.png";
document.getElementsByName('mymedia')[0].muted = true;
}, function() { 
this.src = "images/icons/soundon.png";
document.getElementsByName('mymedia')[0].muted = false;
});
}
</code></pre>
