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

The new node is inserted at the start boundary point of the 范围 . If the new node is to be added to a text 节点 , that 节点 is split at the insertion point, and the insertion occurs between the two text nodes.

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

句法

range.insertNode(newNode);
					

参数

newNode
节点 to insert at the start of the range .

范例

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);
					

规范

规范 状态 注释
DOM
The definition of 'Range.insertNode()' in that specification.
实时标准 无变化
Document Object Model (DOM) Level 2 Traversal and Range Specification
The definition of 'Range.insertNode()' in that specification.
过时 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
insertNode Chrome Yes Edge 12 Firefox 4 IE 9 Opera 9 Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android 10.1 Safari iOS Yes Samsung Internet Android Yes
Collapsed ranges Chrome Yes Edge 12 Firefox 14 IE 9 Opera 9 Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 14 Opera Android 10.1 Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: