How is Node.js created with JavaScript?

Creating Nodes

  • createElement(element_name)
  • createTextNode(string)
  • createComment(string)
  • createDocumentFragment( )

Create Element Node

The createElement(element_name) method is used to create the HTML element specified by tagName, or an HTMLUnknownElement if tagName isn’t recognized. It returns the New Element.


Create Text Node

The createTextNode(string) method is used to create the Text Node with the specified text (string).


Create Comment Node

The createComment(string) method is used to create the Comment Node with the specified string and returns it.

createComment (string)

Document Fragment

  • The DocumentFragment interface represents a minimal document object that has no parent.
  • A common use for Document Fragment is to create one, assemble a DOM subtree within it, then append or insert the fragment into the DOM using Node interface methods such as appendChild( ) or insertBefore( ).
  • Document fragment isn’t part of the active document tree structure, changes made to the fragment don’t affect the document.
  • Doing this moves the fragment’s nodes into the DOM, leaving behind an empty Document Fragment.
  • An empty Document Fragment can be created using the document.createDocumentFragment() method.

Create Document Fragment

The createDocumentFragment() method creates a imaginary Node object, with all the properties and methods of the Node object.

Tagged : / / / /
0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x