我想让id ="a"元素div成为div.b元素中的第一个div.
这是代码:
<div class='b'>
<div>a</div>
<div>a</div>
<div id="a">I want to put this div to be the first div</div>
</div>
Run Code Online (Sandbox Code Playgroud)
使用prepend[API Ref]:
$('#b').prepend($('#a'));
Run Code Online (Sandbox Code Playgroud)
或者,如果它更方便,您可以使用prependTo[API Ref]:
$('#a').prependTo($('#b'));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5435 次 |
| 最近记录: |