2

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.

1
  • 2
    That's not how you check the value; you're setting the display property as relative when you call $('.menu').css('display', 'relative'). Check the API reference for the getter function. Commented Dec 15, 2013 at 21:36

2 Answers 2

5

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
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks this works. Sorry about the typo i wrote Display instead of Position, the typo was here only.
4

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.