0
$("#mute").click(function(){
        $("#audioplayer")[0].muted = $("#audioplayer")[0].muted; 
        $("#message").text("Volume muted");
    })

What I need to achieve is when the users clicks again the button "mute", they will receive another message with "Volume UnMuted", instead of muted, if he clicks it again, switch back to mute, and so on.

2 Answers 2

1

Try the following

(function() {
  var muted = false;
  $("#mute").click(function(){
    muted = !muted;
    $("#audioplayer")[0].muted = muted;

    var msg = muted ? "Volume muted" : "Volume unmuted";
    $("#message").text(msg);
  });
})();
1
  • Thank you, works good, but when I click first time the button, it doens't actually mute the player, changin the 4th like muted = !muted; after $("#audioplayer")[0].muted = muted; did the trick, thank you so much.
    – Special K.
    Apr 7, 2012 at 14:56
1

I would try i this way:

var playerIsMuted = false;

$("#mute").click(function(){
   if (playerIsMuted){
       $("#audioplayer")[0].muted = false;
       $("#message").text("Volume unmuted");
   }else{
       $("#audioplayer")[0].muted = true;
       $("#message").text("Volume muted");
  }
  playerIsMuted = !playerIsMuted;
})

instead of a global variable a attribute attached to the player object can be nicer.

hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.