开发者

JQuery - How to: Duplicate <li> and put it to the end of the <ul>

I have an ordinary ul li. I want to attach an li to the list which is based on the first li in the list.

html

<div id="gallery">
<ul>
<li>Point Nr 1<p>lol</p></li>
<li>Point Nr 2</li>
<li>Point Nr 3</li>
<li>Point Nr 4</li>
</ul>
</div>

pseudo javascript/jquery

$("#gallery ul li").first().duplicate(attachTo:"#gallery ul li")

This is what it looks like:

<div id="gallery">
<ul>
<li>Point Nr 1<p>lol</p></li>
<li>Point Nr 2</li>
<li>Point Nr 3</li>
<li>Point Nr 4</li>
<li>Point Nr 1<p>lol</p></li>
</ul>
</div

How do开发者_C百科 I do this? :)


I think it should be

var ul = $('#gallery ul');
ul.find('li:first').clone(true).appendTo(ul);


Should be:

var $gallery = $('#gallery');
$gallery.find('li:first').clone(true).appendTo($gallery.find('ul'));

Example: http://www.jsfiddle.net/4yUqL/22/

Ref.: .clone()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜