简体   繁体   中英

jQuery div removeClass() / addClass()

I have a particular div element with "testDiv" class;

<div class="testDiv">Content</div>

Now using jQuery I want to remove the testDiv class and add a different class;

jQuery('div').removeClass('testDiv');

Now how can I add a class to this particular div that got its class remove, i fear that if I do jQuery('div').addClass('newClass'); it will add a class to all the other divs present in the page.

怎么样:

jQuery('div.testDiv').addClass('newClass').removeClass('testDiv');
jQuery('div.testDiv').toggleClass("testDiv newClass")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM