Completed

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

This project was successfully completed by ravindrababbar6 for $25 USD in a day.

Get free quotes for a project like this
Project Budget
$10 - $30 USD
Completed In
1 day
Total Bids
6
Project Description

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>

Completed by:
Skills Required

Looking to make some money?

  • Set your budget and the timeframe
  • Outline your proposal
  • Get paid for your work

Hire Freelancers who also bid on this project

    • Forbes
    • The New York Times
    • Time
    • Wall Street Journal
    • Times Online