There are a lot of similar questions and answers, but after trying all solutions I can't figure out what's wrong with my code.
Here is my code
var x = document.getElementsByClassName('xclass1 xclass2 xclass3');
console.log(x);
x.className += ' class4';
console.log(x);
console.log(x.className);
Here is what shows up in the first console.log:
[a.xclass1.xclass2.xclass3]
It shows that it finds the right element
Here is what shows up in the second console.log:
[a.xclass1.xclass2.xclass3, className: "undefined class4"]
And the third one returns this:
undefined class4
Can anyone please explain why className
returns undefined
? I am completely lost here