How do I move list items?

前端 未结 3 591
终归单人心
终归单人心 2021-02-08 03:45

I have a normal unordered list

  • Item 1
  • Item 2
  • Item 3
  • Item 4
3条回答
  •  Happy的楠姐
    2021-02-08 04:24

    Add an id to the unordered list (

      ), and add it after the second child.

      $('#list li').click(function() {
          $(this).insertAfter("#list li:nth-child(1)");
      });
      

      This only works for elements after the first, but an example is on jsFiddle.

提交回复
热议问题