+ 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

23rd Dec 2017, 1:16 PM
Akash Pal
Akash Pal - avatar
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
23rd Dec 2017, 1:30 PM
Leon lit
Leon lit - avatar
+ 6
Thanks @Leon it's working I got to know it all thanks.
23rd Dec 2017, 2:17 PM
Akash Pal
Akash Pal - avatar