Jump to content

dynamically change class names


Go to solution Solved by 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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.