<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Sorting Elements with jQuery</title>
	<atom:link href="http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/</link>
	<description></description>
	<lastBuildDate>Tue, 17 Jan 2012 23:48:58 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Marcio Silveira</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-906</link>
		<dc:creator>Marcio Silveira</dc:creator>
		<pubDate>Tue, 20 Dec 2011 20:56:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-906</guid>
		<description>Thanks a lot, solved my problem.
Based on that I made the function above to sort by attributes:

    function sortElementsByAttribute(elements, atributte, destiny) {
        elements.sort(function (a, b) {
            var compA = $(a).attr(atributte);
            var compB = $(b).attr(atributte);
            return (compA  compB) ? 1 : 0;
        });
        $.each(elements, function (idx, item) { destiny.append(item); });
    }


You can use it with rows of tables, for example, with some personal tribute, for instance:

sortElementsByAttribute($(&quot;#myTable tbody&quot;).children(&quot;tr&quot;).get(), &quot;OrderAttrib&quot;, $(&quot;#myTable tbody&quot;));</description>
		<content:encoded><![CDATA[<p>Thanks a lot, solved my problem.<br />
Based on that I made the function above to sort by attributes:</p>
<p>    function sortElementsByAttribute(elements, atributte, destiny) {<br />
        elements.sort(function (a, b) {<br />
            var compA = $(a).attr(atributte);<br />
            var compB = $(b).attr(atributte);<br />
            return (compA  compB) ? 1 : 0;<br />
        });<br />
        $.each(elements, function (idx, item) { destiny.append(item); });<br />
    }</p>
<p>You can use it with rows of tables, for example, with some personal tribute, for instance:</p>
<p>sortElementsByAttribute($(&#8220;#myTable tbody&#8221;).children(&#8220;tr&#8221;).get(), &#8220;OrderAttrib&#8221;, $(&#8220;#myTable tbody&#8221;));</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brauliobo</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-905</link>
		<dc:creator>brauliobo</dc:creator>
		<pubDate>Mon, 05 Dec 2011 15:29:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-905</guid>
		<description>A more generic function:


function jQuerySort(elements, options) {
  if (typeof options === &#039;undefined&#039;) options = {};
  options.ascending = typeof options.ascending === &#039;undefined&#039; ? 1 : (options.ascending ? 1 : -1);
  var list = elements.get();
  list.sort(function(a, b) {
    var compA = (options.find ? jQuery(a).find(options.find) : jQuery(a)).text().toUpperCase();
    var compB = (options.find ? jQuery(b).find(options.find) : jQuery(b)).text().toUpperCase();
    return options.ascending * ((compA  compB) ? 1 : 0);
  });                   
  parent = elements.first().parent();
  jQuery.each(list, function(index, element) { parent.append(element); });
}</description>
		<content:encoded><![CDATA[<p>A more generic function:</p>
<p>function jQuerySort(elements, options) {<br />
  if (typeof options === &#8216;undefined&#8217;) options = {};<br />
  options.ascending = typeof options.ascending === &#8216;undefined&#8217; ? 1 : (options.ascending ? 1 : -1);<br />
  var list = elements.get();<br />
  list.sort(function(a, b) {<br />
    var compA = (options.find ? jQuery(a).find(options.find) : jQuery(a)).text().toUpperCase();<br />
    var compB = (options.find ? jQuery(b).find(options.find) : jQuery(b)).text().toUpperCase();<br />
    return options.ascending * ((compA  compB) ? 1 : 0);<br />
  });<br />
  parent = elements.first().parent();<br />
  jQuery.each(list, function(index, element) { parent.append(element); });<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: seth</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-904</link>
		<dc:creator>seth</dc:creator>
		<pubDate>Sun, 20 Nov 2011 19:23:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-904</guid>
		<description>Thank you thank you! This is perfect!</description>
		<content:encoded><![CDATA[<p>Thank you thank you! This is perfect!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-893</link>
		<dc:creator>Rob</dc:creator>
		<pubDate>Mon, 15 Aug 2011 22:22:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-893</guid>
		<description>Old bump, but if you want case-sensitive sorting (IE: caps before lowers), simply remove .toUpperCase()</description>
		<content:encoded><![CDATA[<p>Old bump, but if you want case-sensitive sorting (IE: caps before lowers), simply remove .toUpperCase()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Apoteks Salmiak</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-892</link>
		<dc:creator>Apoteks Salmiak</dc:creator>
		<pubDate>Wed, 10 Aug 2011 07:48:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-892</guid>
		<description>This .get() at the end seems unnecessary:
var listitems = mylist.children(&#039;li&#039;).get();

The jquery object is already an array so I believe this should work:
var listitems = mylist.children(&#039;li&#039;);

And instead of appending items individually:
$.each(listitems, function(idx, itm) { mylist.append(itm); });

This seems to works also:
mylist.append(lisitems);</description>
		<content:encoded><![CDATA[<p>This .get() at the end seems unnecessary:<br />
var listitems = mylist.children(&#8216;li&#8217;).get();</p>
<p>The jquery object is already an array so I believe this should work:<br />
var listitems = mylist.children(&#8216;li&#8217;);</p>
<p>And instead of appending items individually:<br />
$.each(listitems, function(idx, itm) { mylist.append(itm); });</p>
<p>This seems to works also:<br />
mylist.append(lisitems);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gui</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-889</link>
		<dc:creator>gui</dc:creator>
		<pubDate>Fri, 15 Jul 2011 07:39:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-889</guid>
		<description>You rock!</description>
		<content:encoded><![CDATA[<p>You rock!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jhanifen</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-887</link>
		<dc:creator>jhanifen</dc:creator>
		<pubDate>Fri, 08 Jul 2011 12:53:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-887</guid>
		<description>This worked great, thanks for the simple tut.</description>
		<content:encoded><![CDATA[<p>This worked great, thanks for the simple tut.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sort a List By Length and Alphabetically Using jQuery &#171; Bertie Baggio&#039;s Wonderland</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-882</link>
		<dc:creator>Sort a List By Length and Alphabetically Using jQuery &#171; Bertie Baggio&#039;s Wonderland</dc:creator>
		<pubDate>Mon, 27 Jun 2011 16:28:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-882</guid>
		<description>[...] functions as I’m not that familiar with either jQuery or javascript. I based my code off code for sorting a list by Dan Sargeant of one more take, so thanks [...]</description>
		<content:encoded><![CDATA[<p>[...] functions as I’m not that familiar with either jQuery or javascript. I based my code off code for sorting a list by Dan Sargeant of one more take, so thanks [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gingerbbm</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-841</link>
		<dc:creator>gingerbbm</dc:creator>
		<pubDate>Fri, 15 Apr 2011 17:08:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-841</guid>
		<description>Nice one, ta.</description>
		<content:encoded><![CDATA[<p>Nice one, ta.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: complex</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-815</link>
		<dc:creator>complex</dc:creator>
		<pubDate>Mon, 07 Mar 2011 22:58:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-815</guid>
		<description>This worked great for sorting the definition terms in my list; 
however, do you know a way to keep the definitions (dd tags) associated with the terms?

One would have a similar problem sorting the headings -- say, all the H2&#039;s -- on a page, keeping that H2&#039;s content associated with the heading.

thanks for any advice.</description>
		<content:encoded><![CDATA[<p>This worked great for sorting the definition terms in my list;<br />
however, do you know a way to keep the definitions (dd tags) associated with the terms?</p>
<p>One would have a similar problem sorting the headings &#8212; say, all the H2&#8242;s &#8212; on a page, keeping that H2&#8242;s content associated with the heading.</p>
<p>thanks for any advice.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 2.395 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-08 04:40:31 -->

