10
09/2014
jquery closest vs parents
closest 向上找到返回第一个
parents 向 htmlElement 找到所有 返回数组然后过滤
.closest() | .parents() |
---|---|
Begins with the current element | Begins with the parent element |
Travels up the DOM tree until it finds a match for the supplied selector | Travels up the DOM tree to the document’s root element, adding each ancestor element to a temporary collection; it then filters that collection based on a selector if one is supplied |
The returned jQuery object contains zero or one element for each element in the original set, in document order | The returned jQuery object contains zero or more elements for each element in the original set, in reverse document order |
via jquery closest