user1645112
user1645112

Reputation: 65

Jquery: append first li child to the end of the list

<ul>
<li>first children</li>
<li>second children</li>
<li>third children</li>
</ul>

How can I use Jquery to remove first children and append it to end of ul list?

Upvotes: 3

Views: 7448

Answers (2)

Ram
Ram

Reputation: 144659

There are many methods than you can use, like appendTo method.

$('ul li:first').appendTo('ul')​​​​;

http://jsfiddle.net/Mb42Z/

or insertAfter method:

var $li = $('ul li');
$li.eq(0).insertAfter($li.last())

Note that element is moved and not removed.

Upvotes: 6

techfoobar
techfoobar

Reputation: 66663

You can use:

var lis = $('ul li');
lis.first().insertAfter(lis.last())​​​​;

Upvotes: 1

Related Questions