Jquery: How to find if element has inline property (not in CSS)
11,014
Solution 1
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
}
Solution 2
There is no display:relative
in CSS. it is position:relative
Author by
Sami A.
Updated on June 04, 2022Comments
-
Sami A. almost 2 years
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.