Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定:X -> B -> C -> D -> Child我希望 jQuery 将所有祖先返回到匹配某个选择器的第一个节点。
X -> B -> C -> D -> Child
jQuery$(Child).parents(X)将只返回X而不是X, B, C, D. 我知道我可以用来parent()手动构建这个数组,但是有更好的方法吗?
$(Child).parents(X)
X
X, B, C, D
parent()
哎呀。找到了:$(Child).parentsUntil(X)
$(Child).parentsUntil(X)
来源:http ://api.jquery.com/parentsUntil/