object - Very Basic setAttribute on JavaScript -
i'm beginner in javascript , can't understand why in simple code, appears in console color.setattribute not function
<style> .red {color:red;} .blue { color: blue;} </style> </head> <body> <p class="red">hello world</p> <script> var color = document.getelementsbyclassname("red"); color.setattribute("class","blue"); </script>
thanks in advance, , sorry if question silly.
document.getelementsbyclassname("red")
returns dom object array object. should write following.
var color=document.getelementsbyclassname("red")[0]; color.setattribute("class","blue");
Comments
Post a Comment