appendChild does not work

僤鯓⒐⒋嵵緔 提交于 2020-01-05 06:58:15

问题


First of all: I'm not much schooled with javascript. So have a problem with the appendChild method. That's my code:

var wrapper = document.getElementsByClassName('innerWrap');
var post = document.createElement('input');
post.style.position = "absolute";
post.style.top = "100px";
document.wrapper.appendChild(post);

Why doesn't it work?

Thanks in advance!


回答1:


getElementsByClassName returns an NodeList, not a Node

So you could try var wrapper = document.getElementsByClassName('innerWrap')[0];




回答2:


Have you tried

wrapper.appendChild(post);

instead of

document.wrapper.appendChild(post); 

?



来源:https://stackoverflow.com/questions/10516736/appendchild-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!