Skip to content

Commit ece34cf

Browse files
dmethvinkswedberg
authored andcommitted
More emphasis about element order with .add() and jQuery()
Fixes gh-240 Closes #435
1 parent 258b3dc commit ece34cf

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

entries/add.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<desc>Add elements to the set of matched elements.</desc>
3838
<longdesc>
3939
<p>Given a jQuery object that represents a set of DOM elements, the <code>.add()</code> method constructs a new jQuery object from the union of those elements and the ones passed into the method. The argument to <code>.add()</code> can be pretty much anything that <code>$()</code> accepts, including a jQuery selector expression, references to DOM elements, or an HTML snippet.</p>
40-
<p>Do not assume that this method appends the elements to the existing collection in the order they are passed to the <code>.add()</code> method. When all elements are members of the same document, the resulting collection from <code>.add()</code> will be sorted in document order; that is, in order of each element's appearance in the document. If the collection consists of elements from different documents or ones not in any document, the sort order is undefined. To create a jQuery object with elements in a well-defined order, use the <code>$(array_of_DOM_elements)</code> signature.</p>
40+
<p>Do not assume that this method appends the elements to the existing collection in the order they are passed to the <code>.add()</code> method. When all elements are members of the same document, the resulting collection from <code>.add()</code> will be sorted in document order; that is, in order of each element's appearance in the document. If the collection consists of elements from different documents or ones not in any document, the sort order is undefined. To create a jQuery object with elements in a well-defined order and without sorting overhead, use the <code>$(array_of_DOM_elements)</code> signature.</p>
4141
<p>The updated set of elements can be used in a following (chained) method, or assigned to a variable for later use. For example:</p>
4242
<pre><code>
4343
$( "p" ).add( "div" ).addClass( "widget" );

entries/jQuery.xml

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ $( "div.foo" ).click(function() {
5757
<p>Internally, selector context is implemented with the <code>.find()</code> method, so <code>$( "span", this )</code> is equivalent to <code>$( this ).find( "span" )</code>.</p>
5858

5959
<h4 id="using-dom-elements">Using DOM elements</h4>
60-
<p>The second and third formulations of this function create a jQuery object using one or more DOM elements that were already selected in some other way.</p>
61-
<p><strong>Note:</strong> These formulations are meant to consume only DOM elements; feeding mixed data to the elementArray form is particularly discouraged.</p>
62-
<p>A common use of this facility is to call jQuery methods on an element that has been passed to a callback function through the keyword <code>this</code>:</p>
60+
<p>The second and third formulations of this function create a jQuery object using one or more DOM elements that were already selected in some other way. When passing an array, each element <em>must</em> be a DOM element; mixed data is not supported. A jQuery object is created from the array elements in the order they appeared in the array; unlike most other multi-element jQuery operations, the elements are not sorted in DOM order.</p>
61+
<p>A common use of single-DOM-element construction is to call jQuery methods on an element that has been passed to a callback function through the keyword <code>this</code>:</p>
6362
<pre><code>
6463
$( "div.foo" ).click(function() {
6564
$( this ).slideUp();

0 commit comments

Comments
 (0)