How to reverse the ordering of list items in an unordered list

前端 未结 8 1024
独厮守ぢ
独厮守ぢ 2020-12-29 17:06

Let\'s say I have an unordered list, like this:

  • Bald Eagle
  • Falcon
  • Condor<
8条回答
  •  生来不讨喜
    2020-12-29 17:20

    Untested, but try:

    var parent = document.getElementById("birds");
    var birdList = parent.getElementsByTagName("li");
    
    for(var i = birdList.length-1; i > 0; --i) {
        parent.appendChild(birdList[i];
    }
    

提交回复
热议问题