0
Replace class attribute data.
For example I had 3 elements <div class="ts primary title"></div> <div class="ts primary menu"></div> <div class="ts primary list"></div> I want to replace primary class to secondary class <div class="ts secondary title"></div> <div class="ts secondary menu"></div> <div class="ts secondary list"></div> can it done by javascript rather than jQuery?
1 Réponse
+ 3
Use classList
var tss = document.getElementsByClassName("ts");
for(var i=0;i<tss.length;i++) {
tss[i].classList.remove("primary");
tss[i].classList.add("secondary");
}
https://code.sololearn.com/WnhQsJT4cc2x/?ref=app