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{ }
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With