user2481398
user2481398

Reputation:

Change a Tag's Class through getElementsByTagName

I want to change the class of all elements with a tag 'input' by using getElementsByTagName. I dont know how to change it's class.I'd tried something but it does'nt work.Please help me.

var myList = document.getElementsByTagName("input");
for(i = 0;i < mylist.length; i++){

    //it doesnt work
    myList[i].className = "btn btn-success";
}

Upvotes: 0

Views: 2356

Answers (1)

therealrootuser
therealrootuser

Reputation: 10914

You want to loop over myList, not mylist, as such:

var myList = document.getElementsByTagName("input");
for (i = 0; i < myList.length; i++) {
    //it does work
    myList[i].className = "btn btn-success";
}

Upvotes: 1

Related Questions