Логика примерно такая:
<div id="container">
<div class="item">
<div class="num">22</div>
</div>
<div class="item">
<div class="num">5</div>
</div>
<div class="item">
<div class="num">18</div>
</div>
<div class="item">
<div class="num">37</div>
</div>
<div class="item">
<div class="num">2</div>
</div>
</div>
<script>
var divs = Array.prototype.slice.call(document.querySelectorAll('#container .item'));
divs.sort(sort);
divs.forEach(putIn, container);
function sort(a, b) {
return getValue(a) > getValue(b);
function getValue(element) {
return Number(element.querySelector(".num").textContent);
}
}
function putIn(item) {
this.appendChild(item);
}
</script>