Skip to content
Related Articles

Related Articles

HTML DOM Range insertNode() Method

Improve Article
Save Article
Like Article
  • Last Updated : 07 Jul, 2020

The insertNode() method inserts a node at the start of the Range.

The updated Range consists of new inserted node before the Range of the last Range content.


range.insertNode( newNode );

Parameters: This method accepts single parameter as mentioned above and described below:

  • newNode: The Node to be inserted at the starting of the range.

Return value: This method does not return any value.

Example: This example shows how to insert a node before the range content using insertNode() method. To Clarify, changes in range content, we had console logged the new range in string text using toString() method.


<!DOCTYPE html>
        HTML DOM range insertNode() method
    <p>Range Content</p>
    <button onclick="insert()">
        Click Here to insert the Node
    <p id="element">Node element </p>
        var range = document.createRange();
        const element = document
        console.log("Before Button Click:", 
        function insert() {
            console.log("After  Button Click:", 


  • Before Click the Button:

  • After Click the Button:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera
  • Internet Explorer

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!