+ 1
Im not able to set attribute using .setAttribute ..pls help
kindly look at the code "Jslova"..and help me with the problem
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>
+ 4
to add class I'm using. gets.classList.add("red")