Let\'s say I have an unordered list, like this:
- Bald Eagle
- Falcon
- Condor<
var birds = document.getElementById('birds');
for(var i = 0, bll = birds.childNodes.length; i < bll; i++) {
birds.insertBefore(birds.childNodes[i], birds.firstChild);
}
You can also do this. It works as follows:
<li>
elements) and return them as a NodeList<ul>
element)Code:
const birdsContainer = document.getElementById("birds");
const birdList = birds.getElementsByTagName("li");
[].slice.call(birdList)
.reverse()
.forEach(bird => birdsContainer.appendChild(bird));