From f33052d7bf526359ce8206afcda9ce70cd595e02 Mon Sep 17 00:00:00 2001 From: igorRovenki Date: Fri, 17 Oct 2014 18:08:27 +0300 Subject: [PATCH] info about sorting int values --- sortElements/README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/sortElements/README.md b/sortElements/README.md index 0b87193..290587f 100644 --- a/sortElements/README.md +++ b/sortElements/README.md @@ -24,6 +24,22 @@ That would result in:
  • Banana
  • Carrot
  • + +If you want to sort simple integer values like: + + + +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 `` elements, but the elements you actually want to move within the DOM are the `` (each ``'s parent): @@ -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/). \ No newline at end of file +See more info here: [http://james.padolsey.com/javascript/sorting-elements-with-jquery/](http://james.padolsey.com/javascript/sorting-elements-with-jquery/).