Patrick Lenz
Patrick Lenz

Reputation: 87

appendChild does not work

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!

Upvotes: 1

Views: 4279

Answers (2)

paulslater19
paulslater19

Reputation: 5917

getElementsByClassName returns an NodeList, not a Node

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

Upvotes: 6

bjornruysen
bjornruysen

Reputation: 850

Have you tried

wrapper.appendChild(post);

instead of

document.wrapper.appendChild(post); 

?

Upvotes: 0

Related Questions