Let\'s say I have an unordered list, like this:
- Bald Eagle
- Falcon
- Condor<
An HTMLCollection is only a read-only view of nodes. In order to manipulate nodes, you have to use one of the various DOM manipulation methods. In your case, there happens to be a shortcut; all you need do is to append the child nodes in reverse order.
var birds = document.getElementById("birds");
var i = birds.childNodes.length;
while (i--)
birds.appendChild(birds.childNodes[i]);
Edit: What's happening is that appendChild
removes the node from the document before appending it. This has two effects: a) it saves you from having to make a copy of the list of nodes and removing them before appending them in reverse order, and b) it reverses the order of nodes as it goes, since it appends the last child first and the first child list.