Toggle visibility property of div Toggle visibility property of div jquery jquery

Toggle visibility property of div


Using jQuery:

$('#play-pause').click(function(){  if ( $('#video-over').css('visibility') == 'hidden' )    $('#video-over').css('visibility','visible');  else    $('#video-over').css('visibility','hidden');});


According to the jQuery docs, calling toggle() without parameters will toggle visibility.

$('#play-pause').click(function(){   $('#video-over').toggle();});

http://jsfiddle.net/Q47ya/


There is another way of doing this with just JavaScript. All you have to do is toggle the visibility based on the current state of the DIV's visibility in CSS.

Example:

function toggleVideo() {     var e = document.getElementById('video-over');     if(e.style.visibility == 'visible') {          e.style.visibility = 'hidden';     } else if(e.style.visibility == 'hidden') {          e.style.visibility = 'visible';     }}