0

When I retrieve items from my list using REST API, I generate rows to an html table but when I try to append it to a table, I get the following errors:

Uncaught TypeError: Node.appendChild: Argument 1 is not an object.

function onQuerySucceeded(data) {

    if(data.d && data.d.results){
        var items = data.d.results
        var listItems = ''
        for (var x = 0; x < items.length; x++) {
            listItems += '<tr>'
            listItems += '<td>' + items[x].ID + '</td>'
            listItems += '<td>' + items[x].ID + '</td>'
            listItems += '<td>' + items[x].ID + '</td>'
            listItems += '<td>' + items[x].ID + '</td>'
            listItems += '</tr>'
        }
    }
    

    document.getElementById("service").appendChild(listItems)   //<---- Error
}

I know it's because listItems is not an object but I'm not sure how get it to where it needs to be.
Any ideas?

2 Answers 2

1

This question is not related to SharePoint, however, you can use HTML DOM innerHTML Property if you want to show constructed HTML inside a DIV.

document.getElementById("service").innerHTML = listItems;

Details on innerHTML: https://www.w3schools.com/jsref/prop_html_innerhtml.asp

0

Or you could try to use jQuery:

$("#service").append(listItems)

Not the answer you're looking for? Browse other questions tagged or ask your own question.