Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Dec 2003
    Location
    Atlanta, GA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Determining the index of an element

    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.

    Targets=document.body.getElementsByTagName("DIV")

    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.


    Stephen

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can not think of a reason why would you need to know it...
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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?
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    New to the CF scene
    Join Date
    Dec 2003
    Location
    Atlanta, GA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #6
    New to the CF scene
    Join Date
    Dec 2003
    Location
    Atlanta, GA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Attached Files Attached Files


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •