Need assistance creating a button to sort divs by data value.

In Progress Posted 7 years ago Paid on delivery
In Progress Paid on delivery

Need jquery/javascript to sort divs by date. Script should sort asc and desc based on a button click. Value z is a null value and should be placed on the bottom always. Tried something like this:

("#sort").click(function() {

$(".date").sort(function(a,b){

var datea =Date($(a).attr("data-date"));

return new Date($(a).attr("data-date")) < new Date($(b).attr("data-date"));

}).each(function(){

$("#mainideas").prepend(this);

})

});

Doesn't work, results aren't consistent.

Below is an example:

<div id="mainideas">

<div class="New allstatus status date" data-date="z">

</div>

<div class="New allstatus status date" data-date="z">

</div>

<div class="New allstatus status date" data-date="Sun Jan 29 00:00:00 GMT 2017">

</div>

<div class="New allstatus status date" data-date="Sat Jan 28 00:00:00 GMT 2017">

</div>

<div class="New allstatus status date" data-date="Mon Feb 6 00:00:00 GMT 2017">

</div>

</div>

JavaScript jQuery / Prototype

Project ID: #12776167

About the project

5 proposals Remote project Active 7 years ago

5 freelancers are bidding on average $23 for this job

saifansari2

I can do it right now as you needed. Develop Web Application, Mobile Application,UI layout with latest Technologies like Angularjs,HTML5,CSS3, Canvasjs Reporting, ionic framework, Jquery,JSON,WCF,Ms Sql Server, MVC or More

$25 USD in 30 days
(18 Reviews)
4.3
kartikeyagupta

Hey this is kartikeya with 3+ years of experience in web development with jquery and other javascript frameworks. I will quite confident about the job. Feel free to ping me

$25 USD in 1 day
(10 Reviews)
3.5