<?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, 07 Sep 2010 15:22:36 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Mariano</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-412</link>
		<dc:creator>Mariano</dc:creator>
		<pubDate>Tue, 07 Sep 2010 15:22:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-412</guid>
		<description>Just what I was looking for, thanks Dan!</description>
		<content:encoded><![CDATA[<p>Just what I was looking for, thanks Dan!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-408</link>
		<dc:creator>Sam</dc:creator>
		<pubDate>Thu, 12 Aug 2010 11:49:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-408</guid>
		<description>Hi guys, back again. I can&#039;t believe this but I got it working perfectly. Now one remaining question. My issues was that I had specified the incorrect value where it says &#039;span&#039; below:

        var compA = $(a).find(&#039;span&#039;).text().toUpperCase();
        var compB = $(b).find(&#039;span&#039;).text().toUpperCase();

I changed it from &#039;span&#039; to &#039;a&#039; (for hyperlinks) and it worked!

Now, my remaining issues is that my list 6 columns wide and I is displaying items alphabetically but in horizontal order, not vertical order. Is there any code I can append to it that can make it list the items in vertical order?</description>
		<content:encoded><![CDATA[<p>Hi guys, back again. I can&#8217;t believe this but I got it working perfectly. Now one remaining question. My issues was that I had specified the incorrect value where it says &#8216;span&#8217; below:</p>
<p>        var compA = $(a).find(&#8216;span&#8217;).text().toUpperCase();<br />
        var compB = $(b).find(&#8216;span&#8217;).text().toUpperCase();</p>
<p>I changed it from &#8216;span&#8217; to &#8216;a&#8217; (for hyperlinks) and it worked!</p>
<p>Now, my remaining issues is that my list 6 columns wide and I is displaying items alphabetically but in horizontal order, not vertical order. Is there any code I can append to it that can make it list the items in vertical order?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-407</link>
		<dc:creator>Sam</dc:creator>
		<pubDate>Thu, 12 Aug 2010 10:51:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-407</guid>
		<description>Dear smart folks,

I have been trying to get this working on a wordpress site but I am not having much luck.

I have a submenu which consists of a list of links. Currently they get generated in order of date, but I just want to have them listed in alphabetical order. I thought maybe I can do this with jquery?

The submenu div is called #projects-sub-menu

I have put your code in my js file, and changed the first line to:

var mylist = $(&#039;#projects-sub-menu&#039;);

I can&#039;t get it working though, my list still shows up in order of date. I am a novice and would really appreciate any guidance.</description>
		<content:encoded><![CDATA[<p>Dear smart folks,</p>
<p>I have been trying to get this working on a wordpress site but I am not having much luck.</p>
<p>I have a submenu which consists of a list of links. Currently they get generated in order of date, but I just want to have them listed in alphabetical order. I thought maybe I can do this with jquery?</p>
<p>The submenu div is called #projects-sub-menu</p>
<p>I have put your code in my js file, and changed the first line to:</p>
<p>var mylist = $(&#8216;#projects-sub-menu&#8217;);</p>
<p>I can&#8217;t get it working though, my list still shows up in order of date. I am a novice and would really appreciate any guidance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rossini</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-404</link>
		<dc:creator>rossini</dc:creator>
		<pubDate>Mon, 02 Aug 2010 14:36:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-404</guid>
		<description>Hi Dan,

thank you very much, Dan... I figured it out a few minutes ago by myself... I have to re-write a bit code to make it work the way it&#039;s intended to run... but I can see clearly now the path to heaven.

Thank you very much for helping me.

And a brilliant solution, of course. Thx...
Oliver</description>
		<content:encoded><![CDATA[<p>Hi Dan,</p>
<p>thank you very much, Dan&#8230; I figured it out a few minutes ago by myself&#8230; I have to re-write a bit code to make it work the way it&#8217;s intended to run&#8230; but I can see clearly now the path to heaven.</p>
<p>Thank you very much for helping me.</p>
<p>And a brilliant solution, of course. Thx&#8230;<br />
Oliver</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dan</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-403</link>
		<dc:creator>dan</dc:creator>
		<pubDate>Mon, 02 Aug 2010 11:59:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-403</guid>
		<description>@rossini - You need to run the sort within the $.get callback, after you append the items.

&lt;pre&gt;
$.get(url, function(d) {
  $(d).find(‘entry’).each(function() {
     //code to append items
   });
   //put sort code here
});
&lt;/pre&gt;

Remember that AJAX calls are asynchronous so you need to run the code at the right time - after it has finished. Currently it is just trying to sort an empty list</description>
		<content:encoded><![CDATA[<p>@rossini &#8211; You need to run the sort within the $.get callback, after you append the items.</p>
<pre>
$.get(url, function(d) {
  $(d).find(‘entry’).each(function() {
     //code to append items
   });
   //put sort code here
});
</pre>
<p>Remember that AJAX calls are asynchronous so you need to run the code at the right time &#8211; after it has finished. Currently it is just trying to sort an empty list</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rossini</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-402</link>
		<dc:creator>rossini</dc:creator>
		<pubDate>Mon, 02 Aug 2010 09:42:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-402</guid>
		<description>The .append in the last comment got &quot;interpreted&quot;. The command was:

&lt;pre&gt;
var mychildren = $(&#039;#listticker&#039;).append(&#039;&lt;a href=&quot;&quot; rel=&quot;nofollow&quot;&gt;&#039;+description+&#039;&lt;/a&gt;&#039;+pubDate+&#039;&#039;);
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>The .append in the last comment got &#8220;interpreted&#8221;. The command was:</p>
<pre>
var mychildren = $('#listticker').append('<a href="" rel="nofollow">'+description+'</a>'+pubDate+'');
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: rossini</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-401</link>
		<dc:creator>rossini</dc:creator>
		<pubDate>Mon, 02 Aug 2010 09:40:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-401</guid>
		<description>Hi Dan, hi all,

thank you so much for your support. I appreciate it very much.

Okay, I get closer :-)

It seems that when having a static UL in the HTML code, it gets sorted as intended.

But I am clearing that static list and adding new ones on document ready, then trying to sort it...

$(document).ready(function(){
	var adminrssfeed = &quot;notesfromadmin.xml&quot;;
	$(&quot;#listticker&quot;).empty();
	$.get(adminrssfeed, function(d) {
	 $(d).find(&#039;entry&#039;).each(function() {
	  var $item = $(this);
	  var description = $item.find(&#039;description&#039;).text();
	  var pubDate = $item.find(&#039;updated&#039;).text();
	  var mychildren = $(&#039;#listticker&#039;).append(&#039;&lt;a href=&quot;&quot; rel=&quot;nofollow&quot;&gt;&#039;+description+&#039;&lt;/a&gt;&#039;+pubDate+&#039;&#039;);
	 });
	});

	var mylist = $(&quot;#listticker&quot;);
	var listitems = mylist.children(&#039;li&#039;).get();
	listitems.sort(function(a,b) {
	 var compA = $(a).find(&#039;span&#039;).text().toUpperCase();
	 var compB = $(b).find(&#039;span&#039;).text().toUpperCase();
	 return (compA  compB) ? 1 : 0;
	});
	$.each(listitems, function(idx, itm) { mylist.append(itm); });

};

This fills the listticker ul element with new entries from an xml file, but the sorting part doesn&#039;t work. I think, this is because I am appending new  elements, but they are not there yet when I try to sort them.

I can send the full code including the xml file and send that to you if you like.

Is there something that I can do after appending the  elements and before sorting them, to make them sortable? :-)

Or am I missing something here?

Thank you in advance,

Oliver</description>
		<content:encoded><![CDATA[<p>Hi Dan, hi all,</p>
<p>thank you so much for your support. I appreciate it very much.</p>
<p>Okay, I get closer <img src='http://www.onemoretake.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>It seems that when having a static UL in the HTML code, it gets sorted as intended.</p>
<p>But I am clearing that static list and adding new ones on document ready, then trying to sort it&#8230;</p>
<p>$(document).ready(function(){<br />
	var adminrssfeed = &#8220;notesfromadmin.xml&#8221;;<br />
	$(&#8220;#listticker&#8221;).empty();<br />
	$.get(adminrssfeed, function(d) {<br />
	 $(d).find(&#8216;entry&#8217;).each(function() {<br />
	  var $item = $(this);<br />
	  var description = $item.find(&#8216;description&#8217;).text();<br />
	  var pubDate = $item.find(&#8216;updated&#8217;).text();<br />
	  var mychildren = $(&#8216;#listticker&#8217;).append(&#8216;<a href="" rel="nofollow">&#8216;+description+&#8217;</a>&#8216;+pubDate+&#8221;);<br />
	 });<br />
	});</p>
<p>	var mylist = $(&#8220;#listticker&#8221;);<br />
	var listitems = mylist.children(&#8216;li&#8217;).get();<br />
	listitems.sort(function(a,b) {<br />
	 var compA = $(a).find(&#8216;span&#8217;).text().toUpperCase();<br />
	 var compB = $(b).find(&#8216;span&#8217;).text().toUpperCase();<br />
	 return (compA  compB) ? 1 : 0;<br />
	});<br />
	$.each(listitems, function(idx, itm) { mylist.append(itm); });</p>
<p>};</p>
<p>This fills the listticker ul element with new entries from an xml file, but the sorting part doesn&#8217;t work. I think, this is because I am appending new  elements, but they are not there yet when I try to sort them.</p>
<p>I can send the full code including the xml file and send that to you if you like.</p>
<p>Is there something that I can do after appending the  elements and before sorting them, to make them sortable? <img src='http://www.onemoretake.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Or am I missing something here?</p>
<p>Thank you in advance,</p>
<p>Oliver</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Senthil Kumar</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-400</link>
		<dc:creator>Senthil Kumar</dc:creator>
		<pubDate>Mon, 02 Aug 2010 09:32:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-400</guid>
		<description>Thanks dude! Exactly what i was looking for! :-)</description>
		<content:encoded><![CDATA[<p>Thanks dude! Exactly what i was looking for! <img src='http://www.onemoretake.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dan</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-399</link>
		<dc:creator>dan</dc:creator>
		<pubDate>Sat, 31 Jul 2010 00:26:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-399</guid>
		<description>Hi rossini. Sorry, I am rather busy at the moment. I find your mixture of jQuery and traditional javascript confuses things uneccessarily, it is much easier to assemble elements with jQuery:

var mylist = $(&#039;#listticker&#039;).append(&#039;&lt;li&gt;&lt;img src=&quot;img/me.png&quot; /&gt;&lt;a href=&quot;&quot; class=&quot;blub&quot;&gt;&#039;+description+&#039;&lt;/a&gt;&lt;span class=&quot;bla&quot;&gt;&#039;+strDateTime+&#039;&lt;/span&gt;&lt;/li&gt;&#039;);

There are a couple of things wrong with your sorting javascript. Firstly, you are missing a semi-colon after the sort function and before the each statement. Secondly your comparison logic (the return statement) is not correct. This works:

$(function() {
    var mylist = $(&#039;#listticker&#039;);
    var listitems = mylist.children(&#039;li&#039;).get();
    listitems.sort(function(a,b) {
        var compA = $(a).find(&#039;span&#039;).text().toUpperCase();
        var compB = $(b).find(&#039;span&#039;).text().toUpperCase();
        return (compA &lt; compB) ? -1 : (compA &gt; compB) ? 1 : 0;
    });
    $.each(listitems, function(idx, itm) { mylist.append(itm); });
});

See &lt;a href=&quot;http://www.jsfiddle.net/Ag29X/&quot; rel=&quot;nofollow&quot;&gt;this demo&lt;/a&gt; at JSFiddle

Hope that helps</description>
		<content:encoded><![CDATA[<p>Hi rossini. Sorry, I am rather busy at the moment. I find your mixture of jQuery and traditional javascript confuses things uneccessarily, it is much easier to assemble elements with jQuery:</p>
<p>var mylist = $(&#8216;#listticker&#8217;).append(&#8216;&lt;li&gt;&lt;img src=&#8221;img/me.png&#8221; /&gt;&lt;a href=&#8221;" class=&#8221;blub&#8221;&gt;&#8217;+description+&#8217;&lt;/a&gt;&lt;span class=&#8221;bla&#8221;&gt;&#8217;+strDateTime+&#8217;&lt;/span&gt;&lt;/li&gt;&#8217;);</p>
<p>There are a couple of things wrong with your sorting javascript. Firstly, you are missing a semi-colon after the sort function and before the each statement. Secondly your comparison logic (the return statement) is not correct. This works:</p>
<p>$(function() {<br />
    var mylist = $(&#8216;#listticker&#8217;);<br />
    var listitems = mylist.children(&#8216;li&#8217;).get();<br />
    listitems.sort(function(a,b) {<br />
        var compA = $(a).find(&#8216;span&#8217;).text().toUpperCase();<br />
        var compB = $(b).find(&#8216;span&#8217;).text().toUpperCase();<br />
        return (compA &lt; compB) ? -1 : (compA &gt; compB) ? 1 : 0;<br />
    });<br />
    $.each(listitems, function(idx, itm) { mylist.append(itm); });<br />
});</p>
<p>See <a href="http://www.jsfiddle.net/Ag29X/" rel="nofollow">this demo</a> at JSFiddle</p>
<p>Hope that helps</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rossini</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/comment-page-1/#comment-398</link>
		<dc:creator>rossini</dc:creator>
		<pubDate>Fri, 30 Jul 2010 17:37:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.onemoretake.com/?p=11#comment-398</guid>
		<description>Dan? Any assistance or hint that you (or anybody) could give? I&#039;d be happy to send you the full source code, if you would like to see it...

I know that you probably are involved in many projects, but maybe you want to help a poor dumbhead with his code...?!

Thx in advance,
Oliver</description>
		<content:encoded><![CDATA[<p>Dan? Any assistance or hint that you (or anybody) could give? I&#8217;d be happy to send you the full source code, if you would like to see it&#8230;</p>
<p>I know that you probably are involved in many projects, but maybe you want to help a poor dumbhead with his code&#8230;?!</p>
<p>Thx in advance,<br />
Oliver</p>
]]></content:encoded>
	</item>
</channel>
</rss>
