working out the order of elements in a containing div

L

libsfan01

hi all

im looking for help on how you can track the order of elements in a
parent div when these elements are dragable (with scriptaculous)?

I tihnk i need to write a function that is called everytime i drag
something, that works out the order of elements in a div. can anyone
help me with this? how would i iterate over the child elements of a
div retrieving their id's in an array.
 
A

ASM

libsfan01 a écrit :
hi all

im looking for help on how you can track the order of elements in a
parent div when these elements are dragable (with scriptaculous)?

Does drag-&-drop change order of these elements, or does that only
change their position ? (styles top, left ... z-index )
I tihnk i need to write a function that is called everytime i drag
something, that works out the order of elements in a div.

Certainly yours elements know themselves where (which position) they
are, you only have to ask them : "where are you ?".
how would i iterate over the child elements of a
div retrieving their id's in an array.


Array of divs direct children of a div

childs = new Array();
var c = document.getElementById('myDiv').getElementsByTagName('DIV');
var k = 0;
for(var i=0; i<c.length; i++)
if('myDiv' == c.parentNode.id) {
childs[k] = c.id;
k++;
}
alert(childs);



Array of all elements direct children of a div

childs = new Array();
var c = document.getElementById('myDiv').getElementsByTagName('*');
var k = 0;
for(var i=0; i<c.length; i++)
if('myDiv' == c.parentNode.id) {
childs[k] = c.id;
k++;
}
alert(childs);
 
R

RobG

libsfan01 said:
hi all

im looking for help on how you can track the order of elements in a
parent div when these elements are dragable (with scriptaculous)?

parentDiv.getElementsByTagName('*') will return all the elements in
order according to the DOM tree. If you want some other order, say
based on spatial position, you'll have to look at the position of each
element and look on the coordinates of whatever reference point suits
(top left or center are two obvious ones).

I tihnk i need to write a function that is called everytime i drag
something, that works out the order of elements in a div. can anyone
help me with this? how would i iterate over the child elements of a
div retrieving their id's in an array.

getElementsByTagName returns a NodeList which is similar to an array in
that it has a length property that you can use to iterate over the
collection. It is also live, which an array is not, so you only need to
get a reference to it once and it will reflect the state of the
collection at the instant you access it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,217
Latest member
IRMNikole

Latest Threads

Top