calmchess Posted June 7, 2013 Share Posted June 7, 2013 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]); } Quote Link to comment https://forums.phpfreaks.com/topic/278913-dynamically-change-class-names/ Share on other sites More sharing options...
Solution calmchess Posted June 7, 2013 Author Solution Share Posted June 7, 2013 while loop to the rescue! while (adminCons0.length) { adminCons0[0].className =roomToChange0; } Quote Link to comment https://forums.phpfreaks.com/topic/278913-dynamically-change-class-names/#findComment-1434761 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.