How to move lists

前端 未结 3 1034
耶瑟儿~
耶瑟儿~ 2021-01-29 07:20

I have something like this:

  • 1
  • 2
  • 3
<
相关标签:
3条回答
  • 2021-01-29 07:43

    This should do the trick for you.

    var length = $('ul li').length;
    
    while (length--) $('ul').append($('ul li')[length]);
    

    Here is a working jsfiddle

    0 讨论(0)
  • 2021-01-29 07:59

    You can use ajax sortable jquery plugin. One of my recommendation tutorial is Sortable Lists Using jQuery UI . Here user can re-order list using cursor pointer.

    0 讨论(0)
  • 2021-01-29 08:00

    No jQuery solution :

    var list = document.getElementsByTagName('ul')[0],
        items = list.getElementsByTagName('li'),
        i = items.length;
    while (i--) list.appendChild(items[i]);
    

    Here is a demo : http://jsfiddle.net/wared/tJaJ9/.


    Based on cookie monster's suggestion :

    var list = document.getElementsByTagName('ul')[0],
        i = list.children.length;
    while (i--) list.appendChild(list.children[i]);
    

    Just for fun :

    var list = document.getElementsByTagName('ul')[0],
        items = Array.prototype.slice.call(list.children);
    while (items.length) list.appendChild(items.pop());
    

    A jQuery one :

    $('ul').append($('li').get().reverse());
    
    0 讨论(0)
提交回复
热议问题