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

En curso Publicado hace 7 años Pagado a la entrega
En curso Pagado a la entrega

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

Nº del proyecto: #12776167

Sobre el proyecto

5 propuestas Proyecto remoto Activo hace 7 años

5 freelancers están ofertando un promedio de $23 por este trabajo

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 Más

$25 USD en 30 días
(18 comentarios)
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 en 1 día
(10 comentarios)
3.5