SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member Mara's Avatar
    Join Date
    Mar 2001
    Location
    Seattle
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation code explaination

    Hello,
    You all have been monumently helpful as I begin my journey into the land of crossbrowser DHTML...
    Here is my next question...

    What is happening with the ns_index?!?!?


    img1=new Image()
    img1.src="fold.gif"
    img2=new Image()
    img2.src="open.gif"
    ns6_index=0

    function change(e){

    if(!document.all&&!document.getElementById)
    return

    if (!document.all&&document.getElementById)
    ns6_index=1

    var source=document.getElementById&&!document.all? e.target:event.srcElement
    if (source.className=="folding"){
    var source2=document.getElementById&&!document.all? source.parentNode.childNodes:source.parentElement.all
    if (source2[2+ns6_index].style.display=="none"){
    source2[0].src="open.gif"
    source2[2+ns6_index].style.display=''
    }
    else{
    source2[0].src="fold.gif"
    source2[2+ns6_index].style.display="none"
    }
    }
    }
    document.onclick=change


    THANK YOU,
    Mara

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    .oO( could have sworn i saw this the other day... )

    The intention is that once ns6_index is set, it will add 1 to collection references.
    The problem is - ie dom specifies that collection indexing starts at 0 - but NS6 specifies the opposite.

    Source2 is a collection of all the children in the same parent structure as the current element (source - which is either event.srcElement or target - but either way the triggering element).

    This collection is basically the same as going through next/previousSiblings...

    The line you've highlighted is a logical clause - dependant on whether or not the 3rd (ie:2, ns:3) element in the collection's style.display == 'none'.

    In other words - this little bundle just queries if the third element under the parent is showing, and if it isn't then it makes it show and does an image swap on the first element (ie:0, ns:1)


    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    SitePoint Member Mara's Avatar
    Join Date
    Mar 2001
    Location
    Seattle
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile



    Thank you SO much...I think I "get it" now!

    Mara

  4. #4
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's ok.

    Let me know if you can't get whatever you're doing
    to work.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---


Bookmarks

Posting Permissions

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