[英]add li to existing ul using jquery
I have 2 divs nested with a ul inside them. 我有2个div嵌套在他们里面的ul。
<div id="slide1">
<div class="images">
<ul>
</ul>
</div>
</div>
I wanted to add a li dynamically to the ul using jquery. 我想使用jquery动态地将一个li添加到ul。 The selector I am using is..
我正在使用的选择器是..
$("#slide1 > div.images ul").append(
It does not work. 这是行不通的。 Where am I wrong?
我哪里错了?
Thanks a lot in advance, 非常感谢提前,
if you want to append a li element to the end of your ul: 如果你想将一个li元素附加到ul的末尾:
$("#slide1 > div.images ul").append($("<li>my new li</li>"));
or if you want to add a li to the beginning of your ul 或者如果你想在你的ul的开头添加一个li
$("#slide1 > div.images ul").prepend($("<li>my new li</li>"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.