Skip to content

Commit 501491b

Browse files
dmethvinkswedberg
authored andcommitted
Note new sane 1.9+ behavior for disconnected elems, ref gh-240
1 parent 0e31d5a commit 501491b

File tree

4 files changed

+5
-11
lines changed

4 files changed

+5
-11
lines changed

entries/after.xml

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ $( "p" ).first().after( $newdiv1, [ newdiv2, existingdiv1 ] );
100100
</code></pre>
101101
<p>Since <code>.after()</code> can accept any number of additional arguments, the same result can be achieved by passing in the three <code>&lt;div&gt;</code>s as three separate arguments, like so: <code>$( "p" ).first().after( $newdiv1, newdiv2, existingdiv1 )</code>. The type and number of arguments will largely depend on the elements that are collected in the code.</p>
102102
</longdesc>
103+
<note id="disconnected-manipulation" type="additional" data-title=".after()"/>
103104
<note id="html-code-execution" type="additional"/>
104105
<example>
105106
<desc>Inserts some HTML after all paragraphs.</desc>

entries/before.xml

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ $( "p" ).first().before( newdiv1, [ newdiv2, existingdiv1 ] );
8080
</code></pre>
8181
<p>Since <code>.before()</code> can accept any number of additional arguments, the same result can be achieved by passing in the three <code>&lt;div&gt;</code>s as three separate arguments, like so: <code>$( "p" ).first().before( $newdiv1, newdiv2, existingdiv1 )</code>. The type and number of arguments will largely depend on how you collect the elements in your code.</p>
8282
</longdesc>
83+
<note id="disconnected-manipulation" type="additional" data-title=".before()"/>
8384
<note id="html-code-execution" type="additional"/>
8485
<example>
8586
<desc>Inserts some HTML before all paragraphs.</desc>

entries/replaceWith.xml

+1-11
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,8 @@ $( "div.third" ).replaceWith( $( ".first" ) );
6363
</code></pre>
6464
<p>This example demonstrates that the selected element replaces the target by being moved from its old location, not by being cloned.</p>
6565
<p>The <code>.replaceWith()</code> method, like most jQuery methods, returns the jQuery object so that other methods can be chained onto it. However, it must be noted that the <em>original</em> jQuery object is returned. This object refers to the element that has been removed from the DOM, not the new element that has replaced it.</p>
66-
<p>As of jQuery 1.4, <code>.replaceWith()</code> can also work on disconnected DOM nodes. For example, with the following code, <code>.replaceWith()</code> returns a jQuery set containing only a paragraph.:</p>
67-
<pre><code>
68-
$( "&lt;div/&gt;" ).replaceWith( "&lt;p&gt;&lt;/p&gt;" );
69-
</code></pre>
70-
<p>The <code>.replaceWith()</code> method can also take a function as its argument:</p>
71-
<pre><code>
72-
$( "div.container" ).replaceWith(function() {
73-
return $( this ).contents();
74-
});
75-
</code></pre>
76-
<p>This results in <code>&lt;div class="container"&gt;</code> being replaced by its three child <code>&lt;div&gt;</code>s. The return value of the function may be an HTML string, DOM element, or jQuery object.</p>
7766
</longdesc>
67+
<note id="disconnected-manipulation" type="additional" data-title=".replaceWith()"/>
7868
<example>
7969
<desc>On click, replace the button with a div containing the same word.</desc>
8070
<code><![CDATA[

notes.xsl

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<xsl:choose>
44
<xsl:when test="@id = 'dimensions-number'">
55
The numbers returned by dimensions-related APIs, including <code><xsl:value-of select="@data-title"/></code>, may be fractional in some cases. Code should not assume it is an integer. Also, dimensions may be incorrect when the page is zoomed by the user; browsers do not expose an API to detect this condition.
6+
<xsl:when test="@id = 'disconnected-manipulation'">
7+
Prior to jQuery 1.9, <code><xsl:value-of select="@data-title"/></code> would attempt to add or change nodes in the current jQuery set if the first node in the set was not connected to a document, and in those cases return a new jQuery set rather than the original set. The method might or might not return a new result depending on the number or connectedness of its arguments! As of jQuery 1.9, these methods always return the original unmodified set and attempting to use .after(), .before(), or .replaceWith() on a node without a parent has no effect--that is, neither the set or the nodes it contains are changed.
68
</xsl:when>
79
<xsl:when test="@id = 'document-order'">
810
Selected elements are in the order of their appearance in the document.

0 commit comments

Comments
 (0)