Move Clicked List Items To Top Of List

Avatar of Chris Coyier
Chris Coyier on

Assuming HTML like this:

<ul>
  <li>one</li>
  <li>two</li>
  <li>three</li>
</ul>

So if “Two” is clicked, move it to the top of the list.

$("li").click(function() {
     
  $(this).parent().prepend($(this));
  
});

Will work for multiple lists…