Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery: How to find if element has inline property (not in CSS)

I have a tag such as:

<div class="menu" style="display:relative;">

..and I am trying to check with:

if ($('.menu').css('display','relative'))

.. the CSS for .menu has display:fixed; so it's ignoring the inline style and returning negative for if.

What's the best way to check the active style attribute on an element regardless if in CSS or inline?

Thanks.

like image 330
Sami A. Avatar asked Dec 19 '25 19:12

Sami A.


2 Answers

With your code you are setting display attribute with relative.
try this:

if ($('.menu').css('display') == 'relative'){
   //your code
}

The problem is that display hasn't attribute relative, maybe you mean position like this:

<div class="menu" style="position:relative;">

and jQuery:

if ($('.menu').css('position') == 'relative'){
       //your code
    }
like image 188
Alessandro Minoccheri Avatar answered Dec 22 '25 07:12

Alessandro Minoccheri


There is no display:relative in CSS. it is position:relative

like image 37
tony Avatar answered Dec 22 '25 09:12

tony



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!