+ 1

Im not able to set attribute using .setAttribute ..pls help

kindly look at the code "Jslova"..and help me with the problem

25th Mar 2017, 6:30 PM
Surya Poojary
Surya Poojary - avatar
2 Respostas
+ 23
<html> <head><title> webpage </title> <script> function magic(){ var gets = document.getElementById("syn"); if(gets != null){ alert("its not null"); } var reveal = gets.innerHTML; var fin = reveal + "Made by JS"; alert(fin); var atr = gets.setAttribute("class","red"); if(gets.getAttribute("class")){ alert("set attribute is set"); }else{ alert("not set"); } } window.onload = magic; </script> </head> <body> <p id = "syn"> This is a paragraph </p> </body> </html>
25th Mar 2017, 6:54 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 4
to add class I'm using. gets.classList.add("red")
25th Mar 2017, 6:56 PM
Yaroslav Pieskov
Yaroslav Pieskov - avatar