getElementsByClassName to change the style of elements when event occurs [duplicate]
As the function name suggests getElementsByClassName returns a collection not just one object. So you need to loop through them and apply the color to it. document.getElementsByClassName() ^_______ Plus your id part is invalid. Id cannot have spaces and also it shouldn’t appear again on the page which is violated by: <th id=”colorswitcher A” onmouseover=”document.getElementsByClassName(‘a’).style.background=’red'”>a</th> … Read more