473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

sorting of div's using javascript

I need a javascript for sorting DIV's based on their ID. some of them
may be nested (all of them have the same class)
e.g. my structure:

'
DIV ID="abc-123" class="myclass"
DIV ID="abc-127" class="myclass"
/DIV
/DIV
DIV ID="abc-124" class="myclass"
/DIV
DIV ID="abc-125" class="myclass"
DIV ID="abc-126" class="myclass"
/DIV
/DIV

and I need a script to cut out all "myclass" divs and place them on the
same position but sorted and unnested like this:
DIV ID="abc-123" class="myclass"
/DIV
DIV ID="abc-124" class="myclass"
/DIV
DIV ID="abc-125" class="myclass"
/DIV
DIV ID="abc-127" class="myclass"
/DIV
DIV ID="abc-128" class="myclass"
/DIV

Can you help me how to do it?

Nov 22 '06 #1
1 1736
TKapler wrote:
I need a javascript for sorting DIV's based on their ID. some of them
may be nested (all of them have the same class)
and I need a script to cut out all "myclass" divs and place them on
the same position but sorted and unnested like this:
Use getElementsByTagName to scan through the list of DIV's.
Inspect each classname. If it's "myclass" then push its ID on to an array.
Sort the array.
Loop through the array and use getElementById to grab a reference to each
DIV
Use appendChild on your target element and pass each DIV, which will
automatically remove it from its previous location.

Hope that helps!

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jack Wayne | last post by:
Hi, I am using MSXML 3.0rc. I have a document similar to the following: <?xml version="1.0"?> <cars> <car name="Mercedes"> <model built="1985" style="Sedan">560 SEL</model> <model...
17
by: Matt Kruse | last post by:
I'm looking for the best JS/CSS solution to add functionality to tables. The only browser which needs to be supported is IE5.5+, but no activeX can be used. to be able to do: - Fixed header row...
0
by: reclusive monkey | last post by:
I copied the following example from MSDN, and it works nicely. However, I want to combine it with another technique I discovered on the IBM Developer site. However, the first method relies upon...
2
by: jab3 | last post by:
Hello - I'm trying to implement a table that will allow the user to sort on each column, like many applicaitons that have tabular data (e-mail, song list, etc). It invovles grabbing the table,...
6
by: Amy | last post by:
for some reasons, i am using two tables. one for the header, one for the body content. has anyone done table sorting in this situation? anyone has a good script for this? thanks
2
by: rrowles2000 | last post by:
Hi, I have four chuncks of html and I'm trying to sort them. see this link. Basically the sort works for alphabetic sort but not for numerics. Any ideas very welcome? I just can't see what I'm...
1
by: dorandoran | last post by:
The sort on the childgrid is not working; nothing happens when I click on the each column header for sort. (I followed Satay's sample: http://www.codeproject.com/KB/aspnet/EditNestedGridView.aspx)...
4
pradeepjain
by: pradeepjain | last post by:
i had posted the same code in javascript area !! this i am posting bcos of different problem. as you can see in ma code there is a dropdown called sort ...its sorts the result by the value he...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.