01-08-2004, 12:17 AM
I'm not sure I will get the terminology correct but how can you determine the index of an element in a collection?
I can do this and it will give me a collection of all the div's.
and I can then use Targets.length to find out how many are in the collection but how can I find out the number of the element selected during a onmousedown event?
Hope I am making myself clear.
01-08-2004, 12:56 AM
I can not think of a reason why would you need to know it...
01-08-2004, 02:34 AM
Is there any specific reason you would like to know the index? There are probably better ways to do what you want than to use indices. So, what is it you are trying to do?
01-08-2004, 03:04 AM
I wouldn't have asked if I didn't have a reason for knowing.
I'm working on a drag and drop script to rearrange images in a photoalbum. It uses a table and divs to hold the images. I have it where you can drag an image from one location to another and it will swap the two images. I want to fix it so when you drag an image to a location and it gets inserted and shuffles the others down rather than swapping.
There may be another way, but I've just about figured a way but it requires me to know where the div holding the first image is in the collection.
01-08-2004, 02:11 PM
Did you know that if you use the DOMElement.insertBefore(newNode, refNode) function on an element present in the document elsewhere, that element is removed from it's current position and moved to be in front of the reference element? This features should do what you want without needing to concern yourself about indices at all.
01-08-2004, 06:43 PM
I figured out a way that will work for us though it currently only works in IE.
There is probably a better, cleaner way to do it and if anyone has any ideas I would appreciate the input.
Attached is a sample script that has 16 small images and allows you to rearrange by drag and drop to different locations in the table. The images snap into place. A radio button allows you to select insert or swap mode. Like I said before it currently works in IE.
Eventually the IMG SRC will be populated from a database and after arranging the images the new sort order will be written back to the database.