Range.insertNode() - Web API 接口参考 编辑
Range.insertNode()
是在Range
的起始位置插入节点的方法。
新节点是插入在 the Range起始位置。如果将新节点添加到一个文本
节点
, 则该节点在插入点处被拆分,插入发生在两个文本节点之间
如果新节点是一个文档片段,则插入文档片段的子节点。
Syntax
range.insertNode(newNode);
Parameters
- newNode
- The
Node
to insert at the start of therange
.
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);
Specifications
Specification | Status | Comment |
---|---|---|
DOM Range.insertNode() | Living Standard | No change |
Document Object Model (DOM) Level 2 Traversal and Range Specification Range.insertNode() | Obsolete | Initial definition |
Browser compatibility
We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | 1.0 (1.7 or earlier) 14.0 (14.0)[1] | 9.0 | 9.0 | (Yes) |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | 1.0 (1.0) 14.0 (14.0)[1] | 9.0 | 9.0 | (Yes) |
[1] Prior to Gecko 14.0 (Firefox 14.0 / Thunderbird 14.0 / SeaMonkey 2.11), this method had no effect on collapsed ranges. Now it behaves as per the specification.
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论