最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node

programmeradmin2浏览0评论

Having a bit of an issue that might be staring me right at the face.

var listitem = document.createElement("li").id = 'list' + x[i]
var listitem = listitem.innerHTML = '<button id="delete' + x[i] + '" class="button action" onclick="deleteuser(\'' + x[i] + '\')">Delete</button>' + x[i]
document.getElementById('userslist').appendChild(listitem)

Having a bit of an issue that might be staring me right at the face.

var listitem = document.createElement("li").id = 'list' + x[i]
var listitem = listitem.innerHTML = '<button id="delete' + x[i] + '" class="button action" onclick="deleteuser(\'' + x[i] + '\')">Delete</button>' + x[i]
document.getElementById('userslist').appendChild(listitem)

The bit of code is in a for loop on Javascript and from the error I can understand that the for loop is working as intended, but it's failing to append to the mentioned list with the error stated above.

Share Improve this question asked Jan 29, 2015 at 14:59 Jarrod FarrellJarrod Farrell 331 gold badge1 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

This is wrong

var listitem = document.createElement("li").id = 'list' + x[i]

It ends up storing the string in the variable listitem and not the object.

Your code should be

var listitem = document.createElement("li");
listitem .id = 'list' + x[i];
发布评论

评论列表(0)

  1. 暂无评论