I'm trying to make a loop that changes the class of an element everytime it is executed. The problem is that
classList.add('something')
requires string and I need to put a variable there, here is my code:
const head = document.createElement('div');
function change_head() {
var head_class = [
{name: "bold"},
{name: "rainbow_head"},
{name: "hut_head"},
{name: "beats_head"}
];
for (let i = 0; i < head_class.length; i += 1){
diffrent_head = head_class[i];
head.classList.add(head_class[i]);
}
};
Hope it is possible to somehow use a variable here.