SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast Trilliann's Avatar
    Join Date
    Apr 2002
    Location
    California
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    loop through all elements

    Here is the problem:
    It's a menu based on an XML document with links.
    I get this XML document and apply an XSLT and display stuff using a CSS and JavaScript.

    When the user clicks on a top-level link, it changes the selected top-level link color, change the bullet image src and opens other links that were hidden under it. When the user clicks again, it changes the color back, changes the bullet image src back and hides the links below it (collapses). Fine.

    But when the user clicks on another top-level link, I want to make sure any open top-level link be collapsed and have the color changed back.

    I'm looping through all elements and if the element classname matches, I set the color or hide the layer or change the bullet image src. In Internet Explorer, I do collection = document.all and loop through the collection, works great. What do I do with Netscape?

    I don't have an array with all the top-level links because it's whatever comes from the XML. Unless I create that array in the XSLT, which doesn't look like a good idea to me...

    Any ideas?

    Thanks,
    Trillie

  2. #2
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Trillian,

    If you're using XML, I'd say just dont' worry about document.all. Instead, use W3C DOM. You'll have to learn it first, but I think all XML browsers should support it and plus it's "correct," while document.all is proprietary. Anyway, a good tutorial to learn it is here (the last part deals exclusively with W3C DOM, but maybe you wanna read it all):

    http://www.pageresource.com/dhtml/ryan/

    Anyway, it should be something like:

    collection = document.getElementsByTagName("*");

    aDog

  3. #3
    SitePoint Enthusiast Trilliann's Avatar
    Join Date
    Apr 2002
    Location
    California
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, aDog. But I need to do that after the page has been transformed by the XSLT. So it's not XML anymore...

  4. #4
    SitePoint Guru bronze trophy blufive's Avatar
    Join Date
    Mar 2002
    Location
    Manchester, UK
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    getElementsByTagName("*") should work just fine on HTML in IE5.5/6, and Netscape 6/7/mozilla. Might even work in Opera 7, too.

    In fact, if you're looking specifically for list elements, you could even try getElementsByTagName("li"), and save some faffing about.

  5. #5
    SitePoint Enthusiast Trilliann's Avatar
    Join Date
    Apr 2002
    Location
    California
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That works wonderfully! Thanks blufive!


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
  •