以前使用 jquery 删除的一些 css 类,例如。
html
<div class="one someclass"></div>
<div class="two otherclass"></div>
<div class="one otherclass"></div>
<div class="two someclass"></div>
jQuery
$('div').removeClass();
这将删除所有类。
现在我想为特定类捕获先前应用的类。
$('div').addClass('someclass')
/* to which previously it was applied someclass in the above html
that is add someclass to first class - one and last class -two*/
$('div').addClass('otherclass')
/* to which previously it was applied otherclass in the above html
that is add otherclass to first class - two and last class -one*/
编辑
就算是这样怎么办
<div class="one someclass"></div>
<div class="otherclass two"></div>
<div class="one otherclass"></div>
<div class="someclass one"></div>