tags:

views:

7526

answers:

3

How can I check the display value of an element

<tr id="pDetails" style="display:none">

$("tr[id='pDetails']").attr("style") gives me 'display:none'

I want to write a jquery script that will return me only the value of display which is 'none'

Is that possible?

A: 

This will return what you asked, but I wouldnt recommend using css like this. Use external CSS instead of inline css.

$("tr[id='pDetails']").attr("style").split(':')[1];
Elzo Valugi
This is bad because it doesn't generalize when the style attribute has more than just display:blah (anything, like width:100, would get mixed into the split(':')[1])
Jared Updike
+4  A: 

Well, for one thing your epression can be simplified:

$("#pDetails").attr("style")

since there should only be one element for any given ID and the ID selector will be much faster than the attribute id selector you're using.

If you just want to return the display value or something, use css():

$("#pDetails").css("display")

If you want to search for elements that have display none, that's a lot harder to do reliably. This is a rough example that won't be 100%:

$("[style*='display: none']")

but if you just want to find things that are hidden, use this:

$(":hidden")
cletus
+12  A: 

Just call css with one argument

  $('#idDetails').css('display');

If I understand your question. Otherwise, you want cletus' answer.

seth