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?

13th Oct 2017, 3:07 AM
林偉雄
林偉雄 - avatar
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
13th Oct 2017, 4:57 AM
Calviղ
Calviղ - avatar