Jump to content

dynamically change class names


calmchess

Recommended Posts

I'm using the following script to change the class names of some elements and then as soon as I'm done changing those elements I want to get all the elements by their new class name and use them.  But when I do this I can't get the new elements. The alert at the bottom does nothing. Can somebody please help me figure this problem out. BTW. I've tried  running this with a for loop instead of reassigning them one by one but I have the same result. I think its a scope problem but I'm just guessing.

 


if(document.getElementsByClassName("admin").length!=0){
var adminCons0=document.getElementsByClassName("admin");
adminCons0[0].className=roomToChange0;
adminCons0[1].className=roomToChange0;
adminCons0[2].className=roomToChange0;
adminCons0[3].className=roomToChange0;
trackArr00 = document.getElementsByClassName(roomToChange0);
alert(trackArr00[0]);
}

Link to comment
https://forums.phpfreaks.com/topic/278913-dynamically-change-class-names/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.