Comments on: Sorting elements with jQuery https://j11y.io/snippets/sorting-elements-with-jquery/ Sun, 22 Mar 2015 15:39:22 +0000 hourly 1 https://wordpress.org/?v=5.0.4 By: Brad https://j11y.io/snippets/sorting-elements-with-jquery/#comment-1886 Fri, 18 Mar 2011 05:33:35 +0000 https://j11y.io/?p=1491#comment-1886 Thanks for the plugin. I was getting sick of writing sorts, so it finally occurred to me to search for a nifty plugin. Yours not only suits the bill, but it has taken the concept so much further by mapping to any collection. Just love it.

I like to use object notation style plugins, so I reconfigured it in that format. I also took the cue from Dan above and included some defaults. I put the code on github as a fork of your ‘jquery-projects’. Really appreciate your contribution.

]]>
By: abdullah https://j11y.io/snippets/sorting-elements-with-jquery/#comment-1885 Sat, 26 Feb 2011 12:22:27 +0000 https://j11y.io/?p=1491#comment-1885 Very Nice informative, but i have some problem when i load content from external page via ajax the alphabetic sorting not working or stop. 🙁

Here is my sorting and ajax code:

r

c

g

d

b

a

s

k

click to load

$(document).ready(function(){
$(‘.ajaxtrigger’).click(function(){
$(‘#target’).load(‘demo2.html’);
});
});

li = jQuery(‘div.sort’),
inverse = true;

$(‘button’).click(function(){
li.sort(function(a, b){
return $(a).text() > $(b).text() ? 1 : -1;
});
});

]]>
By: Gary https://j11y.io/snippets/sorting-elements-with-jquery/#comment-1884 Wed, 09 Feb 2011 23:12:11 +0000 https://j11y.io/?p=1491#comment-1884 Sorry to get all lawyer-like on you, but is this public-domain code? You know how the lawyers want to know about intellectual property rights…

]]>
By: Nathan https://j11y.io/snippets/sorting-elements-with-jquery/#comment-1883 Sat, 29 Jan 2011 19:32:52 +0000 https://j11y.io/?p=1491#comment-1883 The html example in my last post didn’t format well, here is another attempt… I have had to strip out some of the brackets, so you get the idea

div class=thumbnails

div
a href=”#” title=”blah”>img src=”blah” alt=”blah” />/a
h3 a href=”blah” title=”blah”>Text to sort alphabetically ( case sensitive )/a /h3
/div

div
a href=”#” title=”blah”>img src=”blah” alt=”blah” />/a
h3 a href=”blah” title=”blah”>Text to sort alphabetically ( case sensitive )/a /h3
/div

div
a href=”#” title=”blah”>img src=”blah” alt=”blah” />/a
h3 a href=”blah” title=”blah”>Text to sort alphabetically ( case sensitive )/a /h3
/div

div
a href=”#” title=”blah”>img src=”blah” alt=”blah” />/a
h3 a href=”blah” title=”blah”>Text to sort alphabetically ( case sensitive )/a /h3
/div

/div

]]>
By: Nathan https://j11y.io/snippets/sorting-elements-with-jquery/#comment-1882 Sat, 29 Jan 2011 19:27:32 +0000 https://j11y.io/?p=1491#comment-1882 Hello :-
Is it possible to sort in this scenario (code below ).

The comparator is div.thumbnail div h3 a.text() and the element to return/ sort is :- div.thumbnail div

I have tried a few things without success.
Any help greatly appreciated.

<!--HTML-->
 
 
 
<a href="#" title="blah" rel="nofollow"></a>
<a href="blah" title="blah" rel="nofollow">Text to sort alphabetically ( case sensitive )</a>
 
 
 
<a href="#" title="blah" rel="nofollow"></a>
<a href="blah" title="blah" rel="nofollow">Text to sort alphabetically ( case sensitive )</a>
 
 
 
<a href="#" title="blah" rel="nofollow"></a>
<a href="blah" title="blah" rel="nofollow">Text to sort alphabetically ( case sensitive )</a>
]]>
By: Mark Cianciulli https://j11y.io/snippets/sorting-elements-with-jquery/#comment-1881 Tue, 12 Oct 2010 19:39:04 +0000 https://j11y.io/?p=1491#comment-1881 Does this work with jquery 1.3.2? I’m not getting any type of sort.

]]>
By: David https://j11y.io/snippets/sorting-elements-with-jquery/#comment-1880 Mon, 04 Oct 2010 16:43:17 +0000 https://j11y.io/?p=1491#comment-1880 Great solution, I will be using it in an iPhone Web Development I am making. Thanks a lot, simple and easy :9

]]>
By: exoboy https://j11y.io/snippets/sorting-elements-with-jquery/#comment-1879 Wed, 08 Sep 2010 16:13:18 +0000 https://j11y.io/?p=1491#comment-1879 Thanks! This was a great help! I know I have MAAAAAAANY options, but I like to keep things simple and concise. I was about to create my own, but I am very happy with what you put together!

]]>
By: Matt https://j11y.io/snippets/sorting-elements-with-jquery/#comment-1878 Tue, 10 Aug 2010 22:07:43 +0000 https://j11y.io/?p=1491#comment-1878 Nevermind, I fixed it. I’m sure my code is a little haggard, but it looks like this:

$('button#az').click(function(){
  li.sort(function(a, b){
	  return $(a).find('h1').text() &gt; $(b).find('h1').text() ? 1 : -1;
	  $('li').addClass("selected");
  });
});
$('button#date').click(function(){
  li.sort(function(a, b){
	  return $(a).find('h2').text() &gt; $(b).find('h2').text() ? 1 : -1;
  });
});

I’d also to like to note that I’m using jQuery Masonry plug-in and the sorting will not work when Masonry is active. Suggestions?

]]>
By: Matt https://j11y.io/snippets/sorting-elements-with-jquery/#comment-1877 Tue, 10 Aug 2010 20:46:09 +0000 https://j11y.io/?p=1491#comment-1877 I’m needing to sort a list of of work based on date, name, or type. The markup that would be used is below.

<ul>
<li>
<h1>Project Name</h1>
<h2>2010</h2>
<span class=”type”>Commercial</span>
</li>
<li>
<h1>Another Project Name</h1>
<h2>2009</h2>
<span class=”type”>Industrial</span>
</li>
</ul>

How would I go about this?

]]>