I am loading html from a JavaScript array using innerHTML. I would like to sort it alphabetically if I click on the anchor tag. How can i do this? My code is pretty complicated, but 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>';
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 sort the elements alphabetically by name, (#load list h3 a), I tried the sort function, but that didn't work. What is the best way to achieve this?
source
share