I need to sort out the elements that are already displayed in ascending order so that they just rearrange. I need to sort them out by the values in their data-val attributes.
<div id="a" class="item" data-val="6">Item a</div>
<div id="b" class="item" data-val="8">Item b</div>
<div id="c" class="item" data-val="2">Item c</div>
<div id="d" class="item" data-val="5">Item d</div>
<br />
<button onclick="sortOut()">Sort Out</button>
I made an example here: http://jsfiddle.net/quatzael/uKnpa/
I dont know how to do that. I kind of started but it is probably wrong.
I need the function to firstly find out what elements have class called "item" and then those with this class sort out by the value of their data-val attribute.
It has to work in all browsers so the solution should probably involve .appendChild()
Tnx for any help..