javascript - appendChild does not work - Stack Overflow

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

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!

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!

Share Improve this question asked May 9, 2012 at 13:04 Patrick LenzPatrick Lenz 872 silver badges8 bronze badges 1
  • can you try wrapper.appendChild(post); ? – David K Commented May 9, 2012 at 13:05
Add a ment  | 

2 Answers 2

Reset to default 6

getElementsByClassName returns an NodeList, not a Node

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

Have you tried

wrapper.appendChild(post);

instead of

document.wrapper.appendChild(post); 

?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745295882a4621138.html

相关推荐

  • javascript - appendChild does not work - Stack Overflow

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

    4小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信