Take the 2-minute tour ×

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
what does "hidden" mean? i didn't know there was a "hidden" attribute for a div. –  Joseph the Dreamer Apr 4 '12 at 9:21
What are you trying to do? hide the div or store a value in the attributes? –  gdoron Apr 4 '12 at 9:27
add comment

3 Answers

up vote 5 down vote accepted

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():


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

$('#div').is(':visible'); // Or $('#div').is(':hidden')
share|improve this answer
I'd recommend using data-hidden instead of just hidden for html5 compatibility, and using it to jquery.data better. Also you can use numerical representation 0(false), 1(true) –  Panagiotis Apr 4 '12 at 9:23
thanks a lot that's how to do it! –  p0rter Apr 4 '12 at 9:40
@Panagiotis. you better read data docs in the API site. –  gdoron Apr 24 '12 at 17:59
add comment

i think you mean jquery visible

share|improve this answer
add comment

Alternatively you could use


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

This is the same as doing

if ( showOrHide == true ) {
} else if ( showOrHide == false ) {

Hope this helps

share|improve this answer
add comment

Your Answer


