jquery - how to recall the class that was removed previously -
some css classes removed using jquery eg.
html
<div class="one someclass"></div> <div class="two otherclass"></div> <div class="one otherclass"></div> <div class="two someclass"></div>
jquery
$('div').removeclass();
this remove classes.
now want catch applied class specific class.
$('div').addclass('someclass') /* applied someclass in above html add someclass first class - 1 , last class -two*/ $('div').addclass('otherclass') /* applied otherclass in above html add otherclass first class - 2 , last class -one*/
edit
how if this
<div class="one someclass"></div> <div class="otherclass two"></div> <div class="one otherclass"></div> <div class="someclass one"></div>
save before removing.
var classes = $("div")[0].classname; $('div').removeclass(); // ... code later $('div').addclass(classes);
addressing problem word word, may save classes someclass
as:
function saveclasses(classname) { return $(classname)[0].classname.split(/\s+/) .filter(function(c) { return c!=classname; }).join(" "); } var classes = saveclasses(".someclass"); var $div = $('.someclass').removeclass(); // code later $div.addclass(classes);
this add classes except someclass
.
Comments
Post a Comment