Question

How I get the ancestor of a Yahoo UI node of a specific kind? For example, if I have a input element...

var node = A.one('input#_new_WAR_localizededitorportlet_test1');

I want to get its enclosing form. I know how to get the parent node:

var parent = node.get('parentNode');

but not how to (elegantly) go through the tree until reaching the form. For now I am using this

while (node.get('tagName').toLowerCase() != 'form') {
    node = node.get('parentNode');
}

but it is not a really succinct way of doing it.

Is there a better way of doing it?

Était-ce utile?

La solution

Just use the ancestor() method:

node.ancestor('form')
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top