Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

info about sorting int values #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion sortElements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ That would result in:
<li>Banana</li>
<li>Carrot</li>
</ul>

If you want to sort simple integer values like:

<ul>
<li>13</li>
<li>44</li>
<li>7</li>
<li>1</li>
</ul>

You should use parseInt() function to convert string values to integer:

$('li').sortElements(function(a, b){
return parseInt($(a).text()) > parseInt($(b).text()) ? 1 : -1;
});


It also let's you specify what element will be sorted. The current collection's elements will be those referred to as `a` and `b` on each call of the comparator, but you might not want those elements to be the ones to move. E.g. you might want it to be a parent. For example, when sorting a table column, you would sort by the `<td>` elements, but the elements you actually want to move within the DOM are the `<tr>` (each `<td>`'s parent):

Expand All @@ -32,4 +48,4 @@ It also let's you specify what element will be sorted. The current collection's
return this.parentNode;
});

See more info here: [http://james.padolsey.com/javascript/sorting-elements-with-jquery/](http://james.padolsey.com/javascript/sorting-elements-with-jquery/).
See more info here: [http://james.padolsey.com/javascript/sorting-elements-with-jquery/](http://james.padolsey.com/javascript/sorting-elements-with-jquery/).