문제

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?

도움이 되었습니까?

해결책

Just use the ancestor() method:

node.ancestor('form')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top