Argument 1 of Node.appendChild is not an object when trying to append basic html

icecub

General Info
I'm currently working on a chatsystem using a websocket. Aside from the messages, I'm using the same websocket to present the user with a userlist of those currently online.

The Problem
Since a couple of days I've been trying to script all of my Javascript purely in OOP approach. So far it's going pretty well but now I've stumpled upon a error I honestly don't understand:

Argument 1 of Node.appendChild is not an object

The Code
I've narrowed down my code as far as possible to only represent the important parts:

var CB = CB || {};

CB.messages = {
    userListLayout: function(Username){
        var userListTable = "<table class='userTable' data-user='"+ Username +"'><tbody><tr><td><img src='layout/images/default_profile.png'></td><td>" + Username + "</td></tr></tbody></table>";

        return userListTable;
    }
}

CB.users = {
    set: function(Usernames) {
        var List = document.getElementById('usersList'); // Represents an empty div
        var i, j = Usernames.length, ListUser;

        for (i=0; i<j; i++) {
            ListUser = CB.messages.userListLayout(Usernames[i]);
            List.appendChild(ListUser); // Error
        }
    }
}

So the question is: What am I doing wrong and what's the best way to fix it?

Damon

ListUser is a string of HTML. Node.appendChild only accepts a DOM node as an argument.

https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild

You have two options here, either wrap the text you want in a node and use appendChild or keep the current setup and use innerHTML which allows you to add a string to the HTML document:

List.innerHTML += ListUser

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Argument 1 of Node.appendChild is not an object when trying to append basic html

From Dev

html5 drag & drop - TypeError: Argument 1 of Node.appendChild is not an object

From Dev

Internet Explorer throws SCRIPT5022: HierarchyRequestError when trying to appendChild an HTML object from another window

From Dev

Internet Explorer throws SCRIPT5022: HierarchyRequestError when trying to appendChild an HTML object from another window

From Dev

TypeError: Argument 1 of Node.appendChild does not implement interface Node

From Dev

Argument 1 of Node.appendChild does not implement interface Node

From Dev

Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node' error on append tr to a table

From Dev

Object in array is replaced when trying to append it via prepareForSegue

From Dev

Why am I getting an error when trying to append HTML in AngularJS?

From Dev

Text wrapping when trying to include Object in HTML

From Dev

Can't seem to get PHP appendChild to work correctly when importhing html node

From Dev

Error when trying to append in JTextArea

From Dev

Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

From Dev

Getting an error: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

From Dev

Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. in Chrome

From Dev

'NoneType' object is not iterable when list append elements in function call argument list

From Dev

Is append and appendChild getting overwritten?

From Dev

when is argument object created?

From Dev

Cannot append DOM element to DIV node: Uncaught HierarchyRequestError: Failed to execute 'appendChild' on 'Node'

From Dev

When trying to request for OAuth access_token I get: TypeError: encode() argument 1 must be string, not None

From Dev

how to append 'this' object into html in loop

From Dev

Trying to use a JSON object as a argument (Python)

From Dev

NullPointerException when trying to use field array as an argument

From Dev

failed to execute appendchild on node

From Dev

Possible to append existing object in DB? (Node + Mongoose)

From Dev

Fatal error: Uncaught TypeError: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, string given in

From Dev

Object has no method 'appendChild'

From Dev

Leaflet.markercluster onclick error - Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

From Dev

StaleElementReferenceException when trying to reidentify the object

Related Related

  1. 1

    Argument 1 of Node.appendChild is not an object when trying to append basic html

  2. 2

    html5 drag & drop - TypeError: Argument 1 of Node.appendChild is not an object

  3. 3

    Internet Explorer throws SCRIPT5022: HierarchyRequestError when trying to appendChild an HTML object from another window

  4. 4

    Internet Explorer throws SCRIPT5022: HierarchyRequestError when trying to appendChild an HTML object from another window

  5. 5

    TypeError: Argument 1 of Node.appendChild does not implement interface Node

  6. 6

    Argument 1 of Node.appendChild does not implement interface Node

  7. 7

    Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node' error on append tr to a table

  8. 8

    Object in array is replaced when trying to append it via prepareForSegue

  9. 9

    Why am I getting an error when trying to append HTML in AngularJS?

  10. 10

    Text wrapping when trying to include Object in HTML

  11. 11

    Can't seem to get PHP appendChild to work correctly when importhing html node

  12. 12

    Error when trying to append in JTextArea

  13. 13

    Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

  14. 14

    Getting an error: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

  15. 15

    Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. in Chrome

  16. 16

    'NoneType' object is not iterable when list append elements in function call argument list

  17. 17

    Is append and appendChild getting overwritten?

  18. 18

    when is argument object created?

  19. 19

    Cannot append DOM element to DIV node: Uncaught HierarchyRequestError: Failed to execute 'appendChild' on 'Node'

  20. 20

    When trying to request for OAuth access_token I get: TypeError: encode() argument 1 must be string, not None

  21. 21

    how to append 'this' object into html in loop

  22. 22

    Trying to use a JSON object as a argument (Python)

  23. 23

    NullPointerException when trying to use field array as an argument

  24. 24

    failed to execute appendchild on node

  25. 25

    Possible to append existing object in DB? (Node + Mongoose)

  26. 26

    Fatal error: Uncaught TypeError: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, string given in

  27. 27

    Object has no method 'appendChild'

  28. 28

    Leaflet.markercluster onclick error - Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

  29. 29

    StaleElementReferenceException when trying to reidentify the object

HotTag

Archive