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.

3 Answers3

8

Use :contains() and .insertAfter() to move them around:

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

jsFiddle example

j08691
  • 190,436
  • 28
  • 232
  • 252
0

You can store it using detach, and then use append or insertAfter to add again.

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

http://jsfiddle.net/bA7p3/

Ricardo Alvaro Lohmann
  • 25,061
  • 6
  • 80
  • 80
  • This only moves an item to the end of the list. What happens if the OP wants to move it to a different position? Also, the OP said "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_." – j08691 Aug 08 '13 at 19:33
0

Don't know if this is of any interest to you, but it might:

http://jqueryui.com/sortable/

Sam Creamer
  • 4,561
  • 12
  • 29
  • 46