jquery插入元素
append() 方法在被选元素的结尾插入内容。(in)
prepend() 方法在被选元素的开头插入内容。(in)
after() 方法在被选元素之后插入内容。(out)
before() 方法在被选元素之前插入内容。(out)
演示代码:
<div class="testdiv">
<ul>
<li>第一个li标签</li>
</ul>
</div>
<script>
//append
$('.testdiv ul').append('<li>append 插入的li</li>');
//prepend
$('.testdiv ul').prepend('<li>prepend 插入的li</li>');
//after
$('.testdiv ul').after('<li>after 插入的li</li>');
//before
$('.testdiv ul').before('<li>before 插入的li</li>');
</script>
结果:

author:Lik
Endeavoring to powerless, struggling to move yourself.
Endeavoring to powerless, struggling to move yourself.

浙公网安备 33010602011771号