I'm loading a html from a JavaScript array with innerHTML. I'd like to sort it alphabetically, if I click an anchor tag. How can I do that? My code is pretty complex, but the for the question, this is the important part:
<script>
var locations = [['image.png', 'title', 'category', 'city', 'phone', 'address,
zip', 'lat', 'long', '', 'img.png', 'link', '0']];
var load_list_html = "";
load_list_html += '<div data-position="'+
locations[i][6]+
', '+
locations[i][7]+
'" id="maplist" class="map-list-box" data-cat="'+
locations[i][2]+
'"><img class="list-view-img pull-left" src="'+
locations[i][9]+
'"><h3><a class="list-view-title" href="'+
locations[i][10]+
'">'+
locations[i][1]+
'</a></h3><div id="list-rate" class="rateit" data-rateit-value="'+
locations[i][11]+
'" data-rateit-ispreset="true" data-rateit-readonly="true">'+
'</div><p class="list-text">'+
locations[i][8]+
'</p><span class="list-address">'+
locations[i][5]+
', <strong>'+
locations[i][3]+
'</strong>'+
'</span><br><span class="list-phone">'+
locations[i][4]+
'</span></div><!--map-list-box-->';
document.getElementById("load_list").innerHTML = load_list_html;
</script>
<body>
<div id="load_list"></div>
Order by<a id="alphBnt">Alphabetically ordered</a>
</body>
How can I order the elements alphabetically by title, (#load list h3 a), I've tried the sort function, but it didn't work. What is the best way to achieve that?
<a onclick="sortAlphabetically()">...</a>to call some javascript functionsortAlphabetically()(that you need to write).sortAlphabetically()