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 badges1 Answer
Reset to default 7This 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];