Here is the solution: https://jsfiddle.net/mooreinteractive/ffh5t88g/9/
To achieve this, I am first converting a list of divs into an array and then using the .reverse() method on the array. The tricky part comes when converting the array back to HTML...
The initial step involves converting the divs to an array and clearing the original divs from the DOM:
var divs = document.querySelectorAll('div.msg');
var divsArr = Array.prototype.slice.call(divs, 0);
document.querySelector('#cont').innerHTML = '';
Next, I reverse the array and convert it back to HTML using the .map() method of the array:
divsArr.reverse().map(function(htmlObj){
document.querySelector('#cont').appendChild(htmlObj);
});
You can refine this process further for better efficiency. Also, please note that this code assumes the divs are contained within a parent div with id="cont", so you may need to adjust accordingly along with how you clear the original divs.