0

Create a red div cube with JS

I need to create a div with: width: 40px height: 40px background-color: red by a js string, can you help me please? This is my code: var iDiv = document.createElement("div"); iDiv.setAttribute("id","place"); iDiv.style.backgroundColor = "red"; iDiv.style.width = "40px"; iDiv.style.height = "40px";

8th Aug 2018, 5:28 PM
dario
dario - avatar
2 odpowiedzi
+ 3
just add document.body.appendChild(iDiv); if output error, put js code into <script> tag
8th Aug 2018, 7:11 PM
The Ophiuchus
The Ophiuchus - avatar
+ 1
thank you
8th Aug 2018, 7:29 PM
dario
dario - avatar