.prepend()
.prepend( content [, content ] )
- 返回: domtify
插入到元素内部的开头(第一个子元素)。
.prepend( content [, content ] ) from @1.0
- content
- 类型: htmlString|Element|Text|Array|domtify
- 描述: DOM 元素、文本节点、元素和文本节点数组、HTML 字符串或 jQuery 对象,插入到匹配元素集的每个元素的开头。
- content
- 类型: htmlString|Element|Text|Array|domtify
- 描述: 一个或多个DOM 元素、文本节点、元素和文本节点数组、HTML 字符串或 jQuery 对象,插入到匹配元素集的每个元素的开头。
.prepend( function ) from @1.0
- function
该.prepend()
方法将指定的内容插入为 domtify 集合中每个元素的第一个子元素。
想象以下html片段:
html
<h2>Greetings</h2>
<div class="container">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
</div>
您可以创建内容并将其一次插入到多个元素中:
js
d(".inner").prepend("<p>Test</p>")
每个内部<div>
元素都会获得以下新内容:
html
<h2>Greetings</h2>
<div class="container">
<div class="inner">
<p>Test</p>
Hello
</div>
<div class="inner">
<p>Test</p>
Goodbye
</div>
</div>