var udiv = document.createElement('div');
var div = document.createElement("div");
div.style.width = "100px";
div.style.height = "100px";
div.style.background = "red";
div.style.color = "white";
div.innerHTML = "Hello";
div.appendChild(udiv);
I've been trying to get this to work, but when I open the page there's nothing there. I know the Javascript file works because everything else shows up, but the div doesn't. There's no error.
您已将udiv
附加到div
,但从未将div
附加到 DOM。
But both are new elements, Append those elements to an already existing element or to the body
,
.
.
.
div.appendChild(udiv);
document.body.appendChild(div)
您没有将div
对象附加到 DOM
document.body.appendChild(div);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.