how to use JavaScript to change the background color of a class? -
I'm trying to use Javascript to change the background color of your class is called the line, my Javascript and html code are listed below, but this is not working and I'm not sure what the problem is, any help would be greatly appreciated. My HTML code for the button is listed below Change function color () {var row = document.getElementsByClassName ("line"); row.style.backgroundColor = "black"; }
& lt; Input type = "button" id = "btncolour" value = "change color" onclick = "changecolour ();" / & Gt;
getElementsByClassName is just a Orere-object object it is with the elements that match, you have to iterate over the node list and each match has to set the style element
function changes caller () {var row = document.getElementsByClassName ("Line"); For (var i = 0; i & lt; row.length; i ++) {row [i] .style.backgroundColor = "black"; }}
Comments
Post a Comment