difference between append and appendchild code example

Example 1: difference between .append and .appendChild

.append()
This method is used to add an element in form of a Node object or a DOMString (basically means text).

.appendChild()
Similar to the .append method, this method is used to elements in the DOM, but in this case, only accepts a Node object.

--Differences--
1).append accepts Node objects and DOMStrings while .appendChild accepts only Node objects
2).append does not have a return value while .appendChild returns the appended Node object
3).append allows you to add multiple items while appendChild allows only a single item

Example 2: difference between the `.append()` method and the `.appendChild()` method

The ParentNode. append() method inserts a set of Node objects or DOMString objects after the last child of the ParentNode . ... append() allows you to also append DOMString objects, whereas Node. appendChild() only accepts Node objects.

Example 3: .append js

let parent = document.createElement("div")
parent.append("Some text")

console.log(parent.textContent) // "Some text"