Skip to content Skip to sidebar Skip to footer

Check If Hidden Equals True Or False Jquery

i've got this $('#div').attr('hidden', true); i tried: var a = $('#div').attr('hidden'); var b = $('#div').attr('hidden').val(); var c = $('#div').hidden; var a = $('#div').disabl

Solution 1:

attribute will never be true, it can have strings only. jQuery has the data functions for objects other than strings:

$('#div').data("hidden", true);      // set the "hidden" data
var flag = $('#div').data("hidden"); // get the "hidden" data (true)

If you wanted to hide the div, use .hide():

$('#div').hide();

And you check if the div is visible with :visible \ :hidden

$('#div').is(':visible'); // Or $('#div').is(':hidden')

Solution 2:

Alternatively you could use

$('#div').toggle(showOrHide);

where showOrHide is a bool of true of false to hide or show.

This is the same as doing

if ( showOrHide == true ) {
  $('#div').show();
} elseif ( showOrHide == false ) {
  $('#div').hide();
}

Hope this helps

Solution 3:

i think you mean jquery visible

.is(':visible')

Post a Comment for "Check If Hidden Equals True Or False Jquery"