[ 4 posts ]

karolisk

  • Joined: Tue Jun 19, 2012 2:33 am
  • Posts: 5
  • Offline
  • Profile

get parent node with YUI3 by selector

Post Posted: Wed Jun 20, 2012 11:01 pm
+0-
Hi all,

I have a very simple question for which I cannot find answer in documentation - how to get parent node by selector. I found only one without selector.
[node].get('parentNode')

And if there is such functionality I wonder if it's documented.

thanks

Juan Ignacio Dopazo

YUI Contributor

  • Username: jdopazo
  • Joined: Fri Oct 02, 2009 5:39 am
  • Posts: 620
  • Location: Buenos Aires, Argentina
  • Twitter: juandopazo
  • GitHub: juandopazo
  • Gists: juandopazo
  • Offline
  • Profile

Re: get parent node with YUI3 by selector

Post Posted: Thu Jun 21, 2012 4:55 am
+0-
Hey!

I don't think there's a NodeList method for parents, but you can filter the parent nodes by doing nodeList.get('parentNode').filter(selector).

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: get parent node with YUI3 by selector

Post Posted: Thu Jun 21, 2012 6:04 am
+0-
Also from a Node, you can call the Node ancestor method. Without any selector it returns the parent. When used with a selector it returns the closest matching selector.

Code:
<div id="A">
   <span id="B">
        <ol id="C">
           <li id="D">List 1</li>
           <li>List 2</li>
        </ol>
   </span>
</div>

Y.one("#D").ancestor();   // returns the OL #C
Y.one("#D").ancestor().ancestor();   // returns SPAN #B
Y.one("#D").ancestor("span");   // also returns SPAN #B
Y.one("#D").ancestor("div");   // returns DIV #A

karolisk

  • Joined: Tue Jun 19, 2012 2:33 am
  • Posts: 5
  • Offline
  • Profile

Re: get parent node with YUI3 by selector

Post Posted: Fri Jun 22, 2012 4:17 am
+0-
It is exactly what I'm looking for, thanks!
  [ 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