Range.insertNode

  • Revision slug: DOM/range.insertNode
  • Revision title: range.insertNode
  • Revision id: 16811
  • Created:
  • Creator: George3
  • Is current revision? No
  • Comment /* Notes */ 'bug' template instead of URL

Revision Content

{{ DomRef() }}

Summary

Insert a node at the start of a Range.

Syntax

range.insertNode(newNode);

Parameters

newNode 
is a Node.

Example

range = document.createRange();
newNode = document.createElement("p");
newNode.appendChild(document.createTextNode("New Node Inserted Here"));
range.selectNode(document.getElementsByTagName("div").item(0));
range.insertNode(newNode);

Notes

newNode is inserted at the start boundary point of the Range. If the newNodes is to be added to a text Node, that Node is split at the insertion point, and the insertion occurs between the two text Nodes (Blocked by {{ Bug("135922") }})

If newNode is a document fragment, the children of the document fragment are inserted instead.

Specification

insertNode

Revision Source

<p>
{{ DomRef() }}
</p>
<h3 name="Summary"> Summary </h3>
<p>Insert a node at the start of a Range.
</p>
<h3 name="Syntax"> Syntax </h3>
<pre class="eval">range.insertNode(newNode);
</pre>
<h3 name="Parameters"> Parameters </h3>
<dl><dt> newNode </dt><dd> is a Node.
</dd></dl>
<h3 name="Example"> Example </h3>
<pre class="eval">range = document.createRange();
newNode = document.createElement("p");
newNode.appendChild(document.createTextNode("New Node Inserted Here"));
range.selectNode(document.getElementsByTagName("div").item(0));
range.insertNode(newNode);
</pre>
<h3 name="Notes"> Notes </h3>
<p>newNode is inserted at the start boundary point of the Range. If the newNodes is to be added to a text Node, that Node is split at the insertion point, and the insertion occurs between the two text Nodes (Blocked by {{ Bug("135922") }})
</p><p>If newNode is a document fragment, the children of the document fragment are inserted instead.
</p>
<h3 name="Specification"> Specification </h3>
<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level2-Range-method-insertNode">insertNode</a>
</p>
Revert to this revision