Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery - How to get the style display attribute "none / block"

Is there a way to get the style: display attribute which would have either none or block?

DIV :

<div id="ctl00_MainContentAreaPlaceHolder_cellPhone_input_msg_container" class="Error cellphone" style="display: block;">       <p class="cellphone" style="display: block;">Text</p>  </div> 

I know that there is a way to find out if the DIV is hidden or not but in my case this div is dynamically injected so it always shows up as visible false thus I cannot use that :

$j('.Error .cellphone').is(':hidden') 

I am able to get the result "display:block" using :

$j('div.contextualError.ckgcellphone').attr('style') 

Is there a way to get just the value "block" or "none" or is there a better/more efficient way to do this?

like image 629
Murtaza Mandvi Avatar asked Dec 09 '09 17:12

Murtaza Mandvi


People also ask

How do I get the display none element?

display = "none"; To show an element, set the style display property to “block”. document. getElementById("element").

How do I show display none in CSS?

The default display value for most elements is block or inline . This panel contains a <div> element, which is hidden by default ( display: none ). It is styled with CSS, and we use JavaScript to show it (change it to ( display: block ).


2 Answers

You could try:

$j('div.contextualError.ckgcellphone').css('display') 
like image 200
gnarf Avatar answered Sep 29 '22 12:09

gnarf


If you're using jquery 1.6.2 you only need to code

$('#theid').css('display') 

for example:

if($('#theid').css('display') == 'none'){     $('#theid').show('slow');  } else {     $('#theid').hide('slow');  } 
like image 28
raphie Avatar answered Sep 29 '22 12:09

raphie