• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Sort Div Ids

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Can one get all the div iD's in a page, sort them and display it in the sorted order.
example:

This should be

after sorting.

Thanks
 
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
 
Sahana Hegde
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How will I be able to do it?
I tried using the sorttable.js but it did not suit my requirement.
Thanks again in advance.
 
Bear Bibeault
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Break it down into its required steps.

You'll need a way to collect the ids for sorting. A way to sort them. A way to move the elements around.

Start writing some code and post back with any problems that you encounter.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Sahana Hegde:
Hi Guys,

Can one get all the div iD's in a page, sort them and display it in the sorted order.
example:

This should be

after sorting.

Thanks



Yes.

Was I equally helpful?

Try this for getting all divs on page:
var divsCollection = new Array();
divsCollection = document.getElementsByTagName('div');

http://www.w3schools.com/htmldom/dom_nodes_access.asp
Not sure if you need to store it in an array or not....


http://www.w3schools.com/jsref/jsref_sort.asp
If you don't get all the tagnames into an array an dyou have to loop through loading one i'm not sure...either way, use the lovely JS sort() method on the array object (eg divsCollection ).

    Bookmark Topic Watch Topic
  • New Topic