ServerSideSkittles
ServerSideSkittles

Reputation: 2973

jquery clone() and append li

I am trying to clone the current contents of the li with the nested in them also and append them to the ul.

Here is the html

<ul id="gList">
<li><a id="1" href="#"><img src="image.jpg"/></a></li>
<li><a id="2" href="#"><img src="image.jpg"/></a></li>
<li><a id="3" href="#"><img src="image.jpg"/></a></li>
<li><a id="4" href="#"><img src="image.jpg"/></a></li>
</ul>

and my jquery which does not work.

$('ul#gList').clone('li>*').append('ul#gList');

I had done it last night but for some reason sublime has overwritten the file and it has stopped working.

Upvotes: 0

Views: 2686

Answers (1)

atmd
atmd

Reputation: 7490

It's possible you are not firing the code when the ul is ready, try:

$(function () {
    var clones = $('#gList li').clone();
    // set to varaible to make op clear
    $('#gList').append(clones);
});

fiddle

Upvotes: 2

Related Questions