Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

div display if block jquery

Tags:

i am trying trying to find out if a div style display is block then do something here is an e.g

this is just a guess i am tryng to do it in jquery

 if("#toshow":"display" == "block"){   }else{   } 
like image 850
Rickstar Avatar asked Jan 17 '10 23:01

Rickstar


People also ask

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.

How to change display block in jQuery?

You can use the jQuery css() method to change the CSS display property value to none or block or any other value. The css() method apply style rules directly to the elements i.e. inline.


1 Answers

So you want to distinguish between display: block and display: none ? If so, you can better use the is() function in combination with the :visible selector for this:

if ($('#toshow').is(':visible')) {  } else {  } 

This works regardless of if you used display: block, or display: inline, or display: inline-block.

like image 77
BalusC Avatar answered Oct 26 '22 15:10

BalusC