最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - check if hidden equals true or false jQuery - Stack Overflow

programmeradmin5浏览0评论

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.

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.

Share Improve this question asked Apr 4, 2012 at 9:20 p0rterp0rter 9892 gold badges13 silver badges28 bronze badges 2
  • 1 what does "hidden" mean? i didn't know there was a "hidden" attribute for a div. – Joseph Commented Apr 4, 2012 at 9:21
  • What are you trying to do? hide the div or store a value in the attributes? – gdoron Commented Apr 4, 2012 at 9:27
Add a ment  | 

3 Answers 3

Reset to default 9

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

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

i think you mean jquery visible

.is(':visible')
发布评论

评论列表(0)

  1. 暂无评论