Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery style display value

Tags:

jquery

css

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?

like image 796
kaivalya Avatar asked Jul 27 '09 16:07

kaivalya


People also ask

How can check CSS property value in jQuery?

Get a CSS Property Value You can get the computed value of an element's CSS property by simply passing the property name as a parameter to the css() method. Here's the basic syntax: $(selector). css("propertyName");

How check DIV is display or not in jQuery?

Answer: Use the jQuery :visible Selector You can use the jQuery :visible selector to check whether an element is visible in the layout or not. This selector will also select the elements with visibility: hidden; or opacity: 0; , because they preserve space in the layout even they are not visible to the eye.

What is the use of CSS () method in jQuery?

jQuery css() Method The css() method sets or returns one or more style properties for the selected elements. When used to return properties: This method returns the specified CSS property value of the FIRST matched element.


2 Answers

Just call css with one argument

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

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

like image 90
seth Avatar answered Sep 23 '22 17:09

seth


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") 
like image 40
cletus Avatar answered Sep 24 '22 17:09

cletus