You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`.prevAll()` returns elements in the reverse document order. This
can pose issues when used with APIs like `.append()` or `.wrapAll()`.
Document how to deal with the issue with help from `jQuery.uniqueSort()`.
Ref jquery/jquery#5149
Copy file name to clipboardExpand all lines: entries/prevAll.xml
+94-1Lines changed: 94 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@
7
7
<desc>A string containing a selector expression to match elements against.</desc>
8
8
</argument>
9
9
</signature>
10
-
<desc>Get all preceding siblings of each element in the set of matched elements, optionally filtered by a selector.</desc>
10
+
<desc>Get all preceding siblings of each element in the set of matched elements, optionally filtered by a selector, in the reverse document order.</desc>
11
11
<longdesc>
12
12
<p>Given a jQuery object that represents a set of DOM elements, the <code>.prevAll()</code> method searches through the predecessors of these elements in the DOM tree and construct a new jQuery object from the matching elements; the elements are returned in order beginning with the closest sibling.</p>
13
13
<p>The method optionally accepts a selector expression of the same type that we can pass to the <code>$()</code> function. If the selector is supplied, the elements will be filtered by testing whether they match it.</p>
<p>The result of this call is a red background behind items 1 and 2. Since we do not supply a selector expression, these preceding elements are unequivocally included as part of the object. If we had supplied one, the elements would be tested for a match before they were included.</p>
29
+
<p><strong>Note:</strong> Many APIs, like <code><ahref="/append/">append</a></code> or <code><ahref="/wrapAll/">wrapAll</a></code> process node in the order in which they appear in the jQuery object. This can pose issues with APIs like <code>.prevAll()</code> in which the reverse document order is used. Consider the following example:</p>
<p>because "Item 2" gets appended to the wrapper div first. To work around the issue, you may use <code><ahref="/jQuery.uniqueSort/">$.uniqueSort()</a></code> on the <code>.prevAll()</code> output first:</p>
<desc>Locate all the divs preceding the last item and wrap them with a div with class <code>wrapper</code> - with or without <code><ahref="/jQuery.uniqueSort/">$.uniqueSort()</a></code>.</desc>
0 commit comments