Connecting Tech Pros Worldwide Help | Site Map

working out the order of elements in a containing div

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 15th, 2007, 12:45 PM
libsfan01
Guest
 
Posts: n/a
Default working out the order of elements in a containing div

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.


  #2  
Old May 15th, 2007, 02:05 PM
ASM
Guest
 
Posts: n/a
Default Re: working out the order of elements in a containing div

libsfan01 a écrit :
Quote:
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 )
Quote:
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 ?".
Quote:
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').getElementsByTagN ame('DIV');
var k = 0;
for(var i=0; i<c.length; i++)
if('myDiv' == c[i].parentNode.id) {
childs[k] = c[i].id;
k++;
}
alert(childs);



Array of all elements direct children of a div

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


--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
  #3  
Old May 15th, 2007, 02:15 PM
RobG
Guest
 
Posts: n/a
Default Re: working out the order of elements in a containing div

libsfan01 wrote:
Quote:
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).

<URL: http://www.w3.org/TR/DOM-Level-2-Cor...tml#ID-A6C9094 >
Quote:
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.


--
Rob
"We shall not cease from exploration, and the end of all our
exploring will be to arrive where we started and know the
place for the first time." -- T. S. Eliot
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.