I have this html

```
<ul id="theList">
<li><span class="to-date" date-fromdate ="2014-12"     data-todate="2015-01">2015-01</span></li>
<li><span class="to-date" date-fromdate ="2016-12"      data-todate="2017-01">2017-01</span></li>
<li><span class="to-date" date-fromdate ="2014-12"  data-todate="now">now</span></li>
  <li><span class="to-date" date-fromdate ="2015-01"  data-todate="now">now</span></li>
</ul>

```

And the current JavaScript

```
function sortList(list) {
var $list = $(list);
var elems = $.makeArray($list.find("li"));
elems.sort(function(a, b) {
    var $aStr = $(a).find(".to-date").attr("data-todate");
    var $bStr = $(b).find(".to-date").attr("data-todate");

    var $aStrFrom = $(a).find(".to-date").attr("data-fromdate");
    var $bStrFrom = $(b).find(".to-date").attr("data-fromdate");

    if ($aStr != 'now') {
        return true;
    } else {
        return new Date($aStr) < new Date($bStr);
    }
});

$list.html(elems);
}
sortList("#theList");

```

What I want to achieve is that when an items has "now" in the todate attr they are sorted by fromdate attr and placed in top of the the list. Items that dosent have "now" in the todate attr are sorted by todate in the bottom of the list.

How is that possible?

Here is a fiddle

<https://jsfiddle.net/x1z47m0j/>