3

I'm trying to toggle mute by clicking on the video.

I am able to un-mute the video when clicking using this code:

$(document).ready(function(){

    $("video").prop('muted', true);

    $("video").click( function (){
        if( $("video").prop('muted', true) )
        {
            $("video").prop('muted', false)
        }
    });
});

http://jsfiddle.net/Edf8m/7/

Now I just want to be able to click again and it be muted.

user3047579
  • 33
  • 1
  • 1
  • 4

1 Answers1

15

You should be able to solve your problem with a simple boolean toggle.

$("video").click(function () {
    $(this).prop("muted", !$(this).prop("muted"));
});
ZeunO8
  • 422
  • 6
  • 25