| Page 1 of 1 | [ 4 posts ] |
|
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 DopazoYUI Contributor
|
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). |
|
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 |
|
It is exactly what I'm looking for, thanks!
|
| Page 1 of 1 | [ 4 posts ] |
| 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 |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group