Check if jQuery is hidden true or false

I have 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').disabled;

      

I just want to know if the hidden is true or false. somebody knows? my research results relate to shapes and materials.

+3


source to share


3 answers


the attribute will never be true

, it can only have strings.
 jQuery has functions data

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 want to hide div

, use .hide()

:



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

      

And you check if the div is displayed with :visible

\:hidden

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

      

+9


source


I think you mean jquery visible



.is(':visible')

      

+1


source


Alternatively, you can use

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

      

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

This is the same thing to do

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

      

Hope it helps

+1


source







All Articles