Dave's Brain

Browse - Programming Tips - How can I remove some class and add some class in one statement?

Date: 2017apr21
Language: javaScript
Library: jQuery

Q.  How can I remove some class and add some class in one statement?

A.

$('#mything').removeClass('oldclass').addClass('newclass');
There is also toggleClass() that removes a class if its there and adds it if not there.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.