JQuery Find #ID, RemoveClass and AddClass
问题 I have the following HTML <div id="testID" class="test1"> <img id="testID2" class="test2" alt="" src="some-image.gif" /> </div> I basically want to get to #testID2 and replace .test2 class with .test3 class ? I tried jQuery('#testID2').find('.test2').replaceWith('.test3'); But this doesn't appear to work ? Any ideas ? 回答1: jQuery('#testID2').find('.test2').replaceWith('.test3'); Semantically, you are selecting the element with the ID testID2 , then you are looking for any descendent elements