Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have a div with some class and I add some css using Jquery
$('.myClass').css("position","absolute");
After few steps I remove the class myClass
, using
$('.myDiv').removeClass('myClass');
But the style position:absolute
is not removing.
Any help will be much appreciated.
–
–
–
–
Calling addClass
will add a named style from a style-sheet.
Calling css
will apply the styles inline to the element.
To remove the style you applied with css
, simply do
$('.myClass').css("position","");
–
You can't do that using your current code the better way is create a new css class like this
.position-absolute{
the add this class to the div
$('.myDiv').addClass('position-absolute');
and remove the class after use
$('.myClass').css("position","absolute");
That means you are selecting a div having Class named "myClass" and adding that style to that particular div.
But when you are writing
$('.myDiv').removeClass('myClass');
That means you are selecting a div having Class named "myDiv" and removing that class named "myClass". But that class does not include that style("position","absolute"), so it will not be removed.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.