I have a blog that creates a list like this on the php / html page
<div id="unique-id-4" class="blog-entry">Bert blah blah</div> <div id="unique-id-2" class="blog-entry">Andy blah blah</div> <div id="unique-id-3" class="blog-entry">Chas blah blah</div> <div id="unique-id-1" class="blog-entry">Dave blah blah</div>
I want to change the order of sections on a page using javascript.
First , to see how it works, alphabetically sort . (This may be enough for this question). But secondly (what I really want to do) is to sort them by age . I have an array of the name and age of each person I can refer to. Is it possible?
I found this when searching by class
var content = document.getElementsByClassName('blog-entry')
Sorted output can be on one page or on another page - it does not matter. Thanks for any help. I know very little about javascript.
I would like to sort in order 1) Andy, Burt, Hour, Dave (ie "Alphabetically"):
<div id="unique-id-2" class="blog-entry">Andy blah blah</div> <div id="unique-id-4" class="blog-entry">Bert blah blah</div> <div id="unique-id-3" class="blog-entry">Chas blah blah</div> <div id="unique-id-1" class="blog-entry">Dave blah blah</div>
and perfect
2) By age, where in a separate array: Andy = 42, Bert = 18, Chas = 73, Dave = 56; producing
<div id="unique-id-4" class="blog-entry">Bert blah blah</div> <div id="unique-id-2" class="blog-entry">Andy blah blah</div> <div id="unique-id-1" class="blog-entry">Dave blah blah</div> <div id="unique-id-3" class="blog-entry">Chas blah blah</div>
source share