Range.createContextualFragment() - Web APIs 编辑
The Range.createContextualFragment()
method returns a DocumentFragment
by invoking the HTML fragment parsing algorithm or the XML fragment parsing algorithm with the start of the range (the parent of the selected node) as the context node. The HTML fragment parsing algorithm is used if the range belongs to a Document
whose HTMLness bit is set. In the HTML case, if the context node would be html
, for historical reasons the fragment parsing algorithm is invoked with body
as the context instead.
Syntax
documentFragment = range.createContextualFragment(tagString)
Parameters
tagString
- Text that contains text and tags to be converted to a document fragment.
Example
var tagString = "<div>I am a div node</div>";
var range = document.createRange();
// Make the parent of the first div in the document becomes the context node
range.selectNode(document.getElementsByTagName("div").item(0));
var documentFragment = range.createContextualFragment(tagString);
document.body.appendChild(documentFragment);
Specifications
Specification | Status | Comment |
---|---|---|
DOM Parsing and Serialization The definition of 'Range.createContextualFragment()' in that specification. | Working Draft | Initial specification. |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论