[ 4 posts ]

Preston Lytton

  • Username: Preston
  • Joined: Fri May 27, 2011 7:12 am
  • Posts: 5
  • Offline
  • Profile

Selecting Parent Node of Scoped Event Target

Post Posted: Thu Apr 26, 2012 7:18 am
+0-
YUI v 2.9

I have a Nav list with Drop Down tabs that have <a> tags nested in them. When one of the nested tags is clicked I want to change the css of an a tag that is higher up in the node list.
Code:
<ul id#nav>
  <li1>
      <a>nav1</a>
      <div>drop1
          <a><img></a>
          <a>link1</a>
      </div>
  </li1>
  <li2>
      <a>nav2</a>
      <div>drop2
          <a><img></a>
          <a>link2</a>
      </div>
  </li2>
</ul>

here is the code I have working to this point:

Code:
oTopNav.prototype.init = function() {
   YAHOO.util.Event.addListener(this.id,'click',this.changeSectionTrigger);
}

oTopNav.prototype.changeSectionTrigger = function(e) {
   var t = YAHOO.util.Event.getTarget(e);
}


This part is working. The Question: How can I id the top level a tag to change it's css when a lower level a tag is clicked? Would I use delegate? or can I use something like parentNode that works with an id instead of a specific .parent then .sibling order (since the node order is different for the lower level links)?

Preston Lytton

  • Username: Preston
  • Joined: Fri May 27, 2011 7:12 am
  • Posts: 5
  • Offline
  • Profile

Re: Selecting Parent Node of Scoped Event Target

Post Posted: Thu Apr 26, 2012 10:00 am
+0-
I did work this out using a non YUI solution. I am still interested in knowing the YUI way to do this so any knowledge would be appreciated.

thanks

Todd Smith

YUI Contributor

  • Username: stlsmiths
  • Joined: Thu Nov 05, 2009 10:03 am
  • Posts: 675
  • GitHub: stlsmiths
  • Gists: stlsmiths
  • IRC: t_smith
  • Offline
  • Profile

Re: Selecting Parent Node of Scoped Event Target

Post Posted: Thu Apr 26, 2012 12:21 pm
+0-
Hi Preston,

I haven't done a lot of DOM operations with YUI 2.x but you could look into getAncestorByTagName which is in the DOM Utilities. I recommend you search the API there, lots of methods are available.

This would be ALOT easier if you were using YUI 3 :-)

Todd

Preston Lytton

  • Username: Preston
  • Joined: Fri May 27, 2011 7:12 am
  • Posts: 5
  • Offline
  • Profile

Re: Selecting Parent Node of Scoped Event Target

Post Posted: Fri Apr 27, 2012 10:50 am
+0-
Hello Todd,

Yes that is definitely what I needed to be working with. Thanks for your reply. In my research on this I was looking at the Node component in YUI3, appears to be a big improvement.

Thanks again
Preston
  [ 4 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum