How to move lists

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

I have something like this:

  • 1
  • 2
  • 3
<
3条回答
  •  [愿得一人]
    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());
    

提交回复
热议问题