0

I have this html.

<div class="menu">File</div>
<div class="menu">Edit</div>
<div class="menu">Help</div>

And I have this CSS.

.menu { 
    float:left; 
    width:150px; 
    position: relative;
}

For some reason, I need to disable the float:left and position:relative, and return it to "unset" state, if I click on a special button. But this code doesn't work.

function doThat() {
    $('.menu').css ( { "float":"", "position":"" } );
}

How can I do this? The problem is this is not an inline CSS. Thanks.


EDIT: so according to the solution works for me from @alexfreiria, I append the answer here.

function doThat() {
    $('.menu').css ( { "float":"inherit", "position":"inherit" } );
}

And this works on IE. Thank you all!

4
  • Take a look at stackoverflow.com/questions/490910/… for why this doesnt work Commented Mar 27, 2015 at 3:48
  • @DelightedD0D I know. That's why I said "The problem is this is not an inline CSS." So there's no solution to make this work? Commented Mar 27, 2015 at 3:50
  • My bad I missed that satement : ) Commented Mar 27, 2015 at 3:51
  • @DelightedD0D not to worry. :) all is good! Commented Mar 27, 2015 at 3:52

2 Answers 2

4

Change:

function doThat() {
    $('.menu').css ( { "float":"", "position":"" } );
}

To:

function doThat() {
    $('.menu').css ( { "float":"initial", "position":"initial" } );
}

More on the inherit, initial and unset property values.

Sign up to request clarification or add additional context in comments.

3 Comments

Wait, is that means you asked me to use either the inherit or initial, or use the literal "inherit|initial" ?
It's better to specify none and static instead of using initial which is not supported in IE
@Mr.Alien thank you for the clarification! But at least inherit works in my case, and it's in IE. Thank you!
1

This should do:

$('.menu').css ({
   'float': 'none', //initial state is none
   'position': 'static' //initial state is static
});

1 Comment

Thank you! I understand your explanation. But I think the answer from @alexfreiria is more general, because I don't have to remember about what is the initial state, and better yet, I also don't have to remember the inherited state from its parent. But thank you anyway!

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.