+ 6
SetAttribute
Hello, I am having some problems setting the id of the div through setAttribute method when I created a div with createElement method. Can anyone help me? https://code.sololearn.com/WCpQ4s0wK5v0/#js
2 Answers
+ 9
try this ......
window.onload=function() {
var abc = "India is a country";
var a = document.createElement('DIV');
a.setAttribute('id',"demo");
a.innerHTML = abc ;
document.body.appendChild(a);
};
#note ,this is the edited code of akash
+ 6
Thanks @Leon it's working I got to know it all thanks.