I am doing a sorting on div, but unable to perform a sorting. I am using jQuery.fn.sortElements. below is the html.
<div id="sortList">
<div class="list" style="display: block;">
<a onclick="openInfoWindow("10"); return false;" href="#"></a>
<div class="imgClass">
<a onclick="openInfoWindow("10"); return false;" href="#">
<img class="innerImg" alt="" src="img">
</a>
</div>
<div class="inner">
<div class="name">edata</div>
</div>
</div>
<div class="list" style="display: block;">
<a onclick="openInfoWindow("10"); return false;" href="#"></a>
<div class="imgClass">
<a onclick="openInfoWindow("10"); return false;" href="#">
<img class="innerImg" alt="" src="img">
</a>
</div>
<div class="inner">
<div class="name">fdata</div>
</div>
</div>
<div class="list" style="display: block;">
<a onclick="openInfoWindow("10"); return false;" href="#"></a>
<div class="imgClass">
<a onclick="openInfoWindow("10"); return false;" href="#">
<img class="innerImg" alt="" src="img">
</a>
</div>
<div class="inner">
<div class="name">cdata</div>
</div>
</div>
</div>
Below is the jquery code, I have placed an alert to see the result but nothing happens.
$('.sortList').sortElements(function(a, b){
alert($(a).find(".list").children(".inner").find(".name").text().toLowerCase())
return $(a).find(".list").children(".inner").find(".name").text().toLowerCase() > $(a).find(".list").children(".inner").find(".name").text().toLowerCase() ? 1 : -1;
});
Any help is very much appreciated
Try this:
$('#sortList .list').sortElements(function(a, b){
return $(a).children(".inner").find(".name").text().toLowerCase() > $(b).children(".inner").find(".name").text().toLowerCase() ? 1 : -1;
});
See Fiddle
There were a few problems:
Please see JSFiddle: http://jsfiddle.net/qwmq61o5/1/
$('#sortList').children(".list").sortElements(function(a, b) {
return $(a).children(".inner").find(".name").text().toLowerCase() > $(b).children(".inner").find(".name").text().toLowerCase() ? 1 : -1;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With