Sorting nodes is not that simple, you may need to deal with other nodes that might get in the way. Anyhow, here's a function that accepts a NodeList or HTMLCollection, converts it to an array, sorts it, then puts the nodes back in order. Note that the elements are put back at the bottom of the parent element, so any other elements will end up at the top. Anyhow, it demonstrates an approach that you can adapt.
There are many other approaches, including others using DOM methods, beware of any that are based on munging the markup. Also, beware of cloning elements as this may have unwelcome side effects on listeners (they may or may not be removed, depending on the browser and how they've been added).
<script type="text/javascript">
function getText(el) {
return el.textContent || el.innerText || '';
}
function sortElements(nodeList) {
// Assume there's a common parent
var node, parentNode = nodeList[0].parentNode
// Define a sort function
function sortEls(a, b) {
var aText = getText(a);
var bText = getText(b);
return aText == bText? 0 : aText < bText? -1 : 1;
}
// Convert nodelist to an array and remove from the DOM at the same time
var a = [], i = nodeList.length;
while (i--) {
a[i] = parentNode.removeChild(nodeList[i]);
}
// Sort the array
a.sort(sortEls);
// Put elements back in order
i = 0;
while (node = a[i++]) {
parentNode.appendChild(node);
}
}
</script>
<div>0</div>
<div>4</div>
<div>2</div>
<div>3</div>
<div>5</div>
<button onclick="sortElements(document.getElementsByTagName('div'))">Sort</button>