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. Change function color () {var row = document.getElementsByClassName ("line"); row.style.backgroundColor = "black"; }

My HTML code for the button is listed below

  & 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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -