From ce171d666e0bf75e979a63bedf7d0fc0e2a38fef Mon Sep 17 00:00:00 2001 From: Jesse McCarthy Date: Mon, 21 May 2012 15:45:15 -0400 Subject: [PATCH] Clarified that closest() returns 0 or 1 element /per original element/. --- entries/closest.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/entries/closest.xml b/entries/closest.xml index 196b7bd1..280ec593 100644 --- a/entries/closest.xml +++ b/entries/closest.xml @@ -28,7 +28,8 @@ - Get the first element that matches the selector, beginning at the current element and progressing up through the DOM tree. + For each element in the set, get the closest element that matches the selector, by testing the element itself and traversing up through its ancestors. +

Given a jQuery object that represents a set of DOM elements, the .closest() method searches through these elements and their ancestors in the DOM tree and constructs a new jQuery object from the matching elements. The .parents() and .closest() methods are similar in that they both traverse up the DOM tree. The differences between the two, though subtle, are significant:

@@ -47,8 +48,8 @@ - - + +
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 elementThe returned jQuery object contains zero, one, or multiple elementsThe returned jQuery object contains zero or one element for each element in the original setThe returned jQuery object contains zero or more elements for each element in the original set