2

Say I have a simple list

<ul>
    <li>Cats</li>
    <li>Dogs</li>
    <li>Birds</li>
    <li>Snakes</li>
    <li>Spiders</li>
</ul>

I want to remove Birds, and move it to any other position. More than anything, I'll probably have to target the item to move by its text content, and choose where to put it based on the other item's text content.

4

3 回答 3

8

使用:contains().insertAfter()移动它们:

$('li:contains("Birds")').insertAfter('li:contains("Cats")');

jsFiddle 示例

于 2013-08-08T19:05:04.987 回答
0

您可以使用 存储它detach,然后使用appendinsertAfter再次添加。

var $item = $('li:contains("Birds")').detach();
$('ul').append($item);

http://jsfiddle.net/bA7p3/

于 2013-08-08T19:19:07.250 回答
0

不知道您是否对此感兴趣,但它可能:

http://jqueryui.com/sortable/

于 2013-08-08T20:41:25.873 回答