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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts

    "this" keyword help

    I'm working on a dhtml tree menu and was wondering how i can best achieve this. Could i possibly get some pseudocode or something? I have written a very bad script that works, but i need to write one using dom so as to make it more robust. Below is the original script that needs a total makeover. Also, does anyone know a good reference for learning about the this keyword, i believe that i will need it for this project, but i don't really understand it in its entirety.

    http://www.graphics-forum.com/manicp...dMenuTree.html
    Last edited by Antoniohawk; 03-15-2004 at 02:10 AM.

  • #2
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Isn't it already using dom?
    document.getElementById('wtv')
    That's dom isn't it?
    Shawn

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Yes, but i meant designing it to work when there are no ids and just finding the children of the li's and setting their display to none.

  • #4
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    ohhhhhhhhhhhhhh, well that's harder.

    Maybe you could use classes instead of ids.
    Otherwise I think you will need to go in the innerHTML of the ul and find all the <li>s and change them to <li style="display: none;"> or something like that, but I'm really not good at that, so I can't help you..
    Shawn

  • #5
    Regular Coder
    Join Date
    Mar 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey bro,

    Check my tree out. It does just what you want -- finding child nodes, etc.


    http://dhtmlkitchen.com/scripts/animtree/

    You can d/l and look at the source to get some ideas.

    Basically, a menu a has:
    items - childnodes with class menuNode
    allItems - descendants with class menuNode

    This allows for unlimited nesting. It's naively simple approach and allows me to do other fancy stuff with it.

    It's not free, so if you're gonna deploy it, please purchase a license. I may soon offer up an OSD license (open-source developers).

  • #6
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Thanks Dhtml Kitchen. I don't want to pay for the menu, yet I want to learn from it, so what should I do?

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think your question answers itself...

    If in the meantime (while you're figuring out how he did it), you need to use his menu, then pay for it. Pretty simple logic in my book. At least that's my logic, I could be wrong...

    Most of the code that people provide here is free, but if they ask for a paypal donation, or a fee for using it, it's a good gesture to shoot the creator what they require for you to reuse their code.

    It might just keep them alive to code even more useful stuff.
    Last edited by whammy; 03-16-2004 at 03:43 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #8
    Regular Coder
    Join Date
    Mar 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by whammy

    It might just keep them alive to code even more useful stuff.
    Yep. Ramen soup gets old fast, hehe.

  • #9
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Thanks for all of your help Dhtml Kitchen, but I can't afford your menu tree. I'm only 15 and currently don't even have a job. I'm pretty sure that if I work at it, I can get it to work.

  • #10
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    As I started working on my tree, I came across a problem. If I have the following code, how do I tell the function that what I clicked is the thing that I want to do something with. I really don't want to make an id for every single occurence. In other words, what goes where there is a "?",
    Code:
    function door(obj) {
      ...do stuff to whatever was clicked...
    }
    
    <ul id="menuTree">
      <li class="parent"><a href="#" onClick="door( ? )">Fish</a>
        <ul class="item">
          <li><a href="#">Salmon</a></li>
          <li><a href="#">Bass</a></li>
          <li><a href="#">Trout</a></li>
          <li><a href="#">Catfish</a></li>
          <li><a href="#">Cod</a></li>
        </ul>
      </li>
      <li class="parent"><a href="#" onClick="door( ? )">Birds</a>
        <ul class="item">
          <li><a href="#">Sparrow</a></li>
          <li><a href="#">Finch</a></li>
          <li><a href="#">Blue Jay</a></li>
          <li><a href="#">Chickadee</a></li>
        </ul>
      </li>
    </ul>
    Last edited by Antoniohawk; 03-17-2004 at 03:41 AM.

  • #11
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I beleive it goes something like this.object but I'm not sure.

    door(this.object)
    Shawn

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    <a href="#" onClick="door( this )">Fish</a>

    function door(obj) {
    alert(obj.parentNode); //alerts parent node of the link
    //...do stuff to whatever was clicked...
    }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #13
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Exactly what I needed, thank you Glenn.

  • #14
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    GlennGV to the rescue!!!
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #15
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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