check if hidden equals true or false jQuery

对着背影说爱祢 提交于 2020-01-04 02:08:31

问题


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

i just want to know whether hidden is true or false. does anybody know? my research results are all about forms and inputs.


回答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')



回答2:


i think you mean jquery visible

.is(':visible')



回答3:


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();
} else if ( showOrHide == false ) {
  $('#div').hide();
}

Hope this helps



来源:https://stackoverflow.com/questions/10008312/check-if-hidden-equals-true-or-false-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!