Re: [jQuery] Reorder list numerically based on attribute?

2009-11-24 Thread Alexandru Adrian Dinulescu
Sorry to highjack this, but Karl could you somehow describe exactly what
that function does, my js is pretty rusty but i would like to understand how
it works.

Thanks
---
Alexandru Dinulescu
Web Developer
(X)HTML/CSS Specialist
Expert Guarantee Certified Developer
XHTML: http://www.expertrating.com/transcript.asp?transcriptid=1879053
CSS : http://www.expertrating.com/transcript.asp?transcriptid=1870619
Odesk Profile: http://www.odesk.com/users/~~3a2d7f591313701b
RentACoder Profile:
http://www.rentacoder.com/RentACoder/DotNet/SoftwareCoders/ShowBioInfo.aspx?lngAuthorId=6995323

LinkedIn Profile: http://ro.linkedin.com/in/alexandrudinulescu
XHTML/CSS/jQuery Blog - http://alexdweb.com/blog
MainWebsite: http://alexdweb.com



On Tue, Nov 24, 2009 at 6:54 AM, Karl Swedberg k...@englishrules.comwrote:


 Something like this might work...

 var items = $('li').get();
 items.sort(function(a, b) {
 var relA = +$(a).attr('rel');
 var relB = +$(b).attr('rel');

  if (relA  relB) { return 1; }
  if (relA  relB) { return -1; }
  return 0;
 });
 for (var i=0; i items.length; i++) {
 $('.list').append(items[i]);
 }

 --Karl

 
 Karl Swedberg
 www.englishrules.com
 www.learningjquery.com




 On Nov 23, 2009, at 8:21 PM, welshy1984 wrote:

 I am wondering if it is possible to reorder a unordered list based on
 the list items 'rel' attribute?

 i have a list of items that change dynamically (its linked in with
 google maps, the 'rel' attribute of the list item is updated with the
 new distance from the google map marker icon when the marker is moved)
 and i want it to update the list ordering each time a 'rel' attribute
 changes.

 i had a good look about, but i cant find anything for numerical
 ordering (its all alphabetical) so im hoping somebody here could help?

 my list essientially looks like this:

 ul
 li rel=42.53Place One/li
 li rel=51.21Place Two/li
 li rel=98.32Place Three/li
 /ul

 i'd be greatful for any help!





[jQuery] Reorder list numerically based on attribute?

2009-11-23 Thread welshy1984
I am wondering if it is possible to reorder a unordered list based on
the list items 'rel' attribute?

i have a list of items that change dynamically (its linked in with
google maps, the 'rel' attribute of the list item is updated with the
new distance from the google map marker icon when the marker is moved)
and i want it to update the list ordering each time a 'rel' attribute
changes.

i had a good look about, but i cant find anything for numerical
ordering (its all alphabetical) so im hoping somebody here could help?

my list essientially looks like this:

ul
li rel=42.53Place One/li
li rel=51.21Place Two/li
li rel=98.32Place Three/li
/ul

i'd be greatful for any help!


Re: [jQuery] Reorder list numerically based on attribute?

2009-11-23 Thread Karl Swedberg


Something like this might work...

var items = $('li').get();
items.sort(function(a, b) {
var relA = +$(a).attr('rel');
var relB = +$(b).attr('rel');

 if (relA  relB) { return 1; }
 if (relA  relB) { return -1; }
 return 0;
});
for (var i=0; i items.length; i++) {
$('.list').append(items[i]);
}

--Karl


Karl Swedberg
www.englishrules.com
www.learningjquery.com




On Nov 23, 2009, at 8:21 PM, welshy1984 wrote:


I am wondering if it is possible to reorder a unordered list based on
the list items 'rel' attribute?

i have a list of items that change dynamically (its linked in with
google maps, the 'rel' attribute of the list item is updated with the
new distance from the google map marker icon when the marker is moved)
and i want it to update the list ordering each time a 'rel' attribute
changes.

i had a good look about, but i cant find anything for numerical
ordering (its all alphabetical) so im hoping somebody here could help?

my list essientially looks like this:

ul
li rel=42.53Place One/li
li rel=51.21Place Two/li
li rel=98.32Place Three/li
/ul

i'd be greatful for any help!