Element.insertAdjacentHTML(position, text)
来源:互联网 发布:java数组的使用 编辑:程序博客网 时间:2024/05/18 12:37
insertAdjacentHTML()方法是将制定的文本(text)解析为HTXL或者XML后插入到制定的位置(position)处,而且不会影响到Element内部已经存在的节点
语法:Element.insertAdjacentHTML(position, text)
其中position的值是相对于element来说的,并且有且只有以下几种情况:
- beforebegin 在element元素之前
- afterbegin 在element元素第一个节点之前
- beforeend 在element 元素最后一个节点之后
- afterend 在element元素之后
text 是字符串,会被解析成 HTML 或 XML,并插入到 DOM 树中。
位置名称示意:
<!-- beforebegin --><p><!-- afterbegin -->foo<!-- beforeend --></p><!-- afterend -->
注意: 只有当元素节点在一个DOM树中,且有一个父元素时,beforebegin 和 afterend 位置才会起作用。
// <div id="one">one</div> var d1 = document.getElementById('one'); d1.insertAdjacentHTML('afterend', '<div id="two">two</div>');// 此时,新结构变成:// <div id="one">one</div><div id="two">two</div>
浏览器兼容性:
https://developer.mozilla.org/zh-CN/docs/Web/API/Element/insertAdjacentHTML
0 0
- Element.insertAdjacentHTML(position, text)
- insertAdjacentHTML
- find-position-element-sorted-array-infinite-numbers
- Raphael.js API 之Element.remove(),Element.removeData(),paper.text(),Element.node(),Element.onDragOver
- c# rich text box add text into cursor position
- insertAdjacentHTML方法
- insertAdjacentHTML用法
- insertAdjacentHTML方法
- insertAdjacentHTML 笔记
- insertAdjacentHTML方法
- WP7 报 Element is already the child of another element. [Line: 0 Position: 0]
- 给定element,求此element在list中的 index or position
- Append text to TextArea in the currentcursor position
- XmlPullParser 解析不到END_DOCUMENT,XmlPullParserException: Unexpected token (position:TEXT
- android org.xmlpull.v1.XmlPullParserException: Unexpected token (position:TEXT ???@
- ABAP-Download/Upload text element into local file
- LINQ To XML:修改element, a comment, text node
- 修改系统DATA ELEMENT的文本 Text Enhancement
- 概率质量函数(Probability Mass Function)和期望课程笔记
- 《Java 2 实用教程》读书笔记(二)
- HTML 5 的自定义 data-* 属性和jquery的data()方法的使用
- Android 安全相关技巧 --正确使用ADB
- CADisplayLink
- Element.insertAdjacentHTML(position, text)
- 小白书贪心之区间选点问题
- 使用scrapy抓取糗事百科
- Annotation(注解)的简单理解
- android 自定义进度条下载apk并更新
- 九度OJ+贪心二分+最大值最小化都是这样做的。
- 详解js中的object对象
- 向左向右(RadioGroup组与onCheckedChanged)
- MongoDB学习—(2)shell的基本操作