26
Jun
2012

How to remove a CSS class using jQuery

Posted in: jQuery No Comments

jquery_logo
We have learned how to add a CSS class using jQuery to any element in this post. But this time we will check how we can remove a CSS class from any element.

Step 1:
Write some text under class someclass and removeme

<div class="someclass removeme">
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
</div>

Step 2:
Add some css style to class removeme

.removeme {
color: red;
font-weight: bold;
}

At this stage our page looks like this:

Step 3:
Add jQuery library in head section.

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

Step 4:
Now we will add jQuery code in head section and tell it to find class someclass and remove class removeme from it.

<script type="text/javascript">
$(document).ready(function(){
$(".someclass").removeClass('removeme');
});
</script>

Done!!!
Click below link to see the change.

About the Author

Name: Ravi Shekhar
I love learning and sharing web stuffs.

Share this post

Twitter Facebook Google Buzz Digg StumbleUpon Delicious Technorati

Leave a Reply