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
Copy file name to clipboardExpand all lines: entries/jQuery.xml
+8-8
Original file line number
Diff line number
Diff line change
@@ -173,8 +173,8 @@ $( myForm.elements ).hide();
173
173
<p>If a string is passed as the parameter to <code>$()</code>, jQuery examines the string to see if it looks like HTML (i.e., it starts with <code><tag ... ></code>). If not, the string is interpreted as a selector expression, as explained above. But if the string appears to be an HTML snippet, jQuery attempts to create new DOM elements as described by the HTML. Then a jQuery object is created and returned that refers to these elements. You can perform any of the usual jQuery methods on this object:</p>
<p>For explicit parsing of a string to HTML, use the <ahref="/jQuery.parseHTML/">$.parseHTML()</a> method.</p>
176
-
<p>By default, elements are created with an <code>ownerDocument</code> matching the document into which the jQuery library was loaded. Elements being injected into a different document should be created using that document, e.g., <code>$("<p>hello iframe</p>", $("#myiframe").prop("contentWindow").document)</code>.</p>
177
-
<p>If the HTML is more complex than a single tag without attributes, as it is in the above example, the actual creation of the elements is handled by the browser's <code>innerHTML</code> mechanism. In most cases, jQuery creates a new <div> element and sets the innerHTML property of the element to the HTML snippet that was passed in. When the parameter has a single tag (with optional closing tag or quick-closing) — <code>$( "<img />" )</code> or <code>$( "<img>" )</code>, <code>$( "<a></a>" )</code> or <code>$( "<a>" )</code> — jQuery creates the element using the native JavaScript <code>createElement()</code> function.</p>
176
+
<p>By default, elements are created with an <code>.ownerDocument</code> matching the document into which the jQuery library was loaded. Elements being injected into a different document should be created using that document, e.g., <code>$("<p>hello iframe</p>", $("#myiframe").prop("contentWindow").document)</code>.</p>
177
+
<p>If the HTML is more complex than a single tag without attributes, as it is in the above example, the actual creation of the elements is handled by the browser's <code>.innerHTML</code> mechanism. In most cases, jQuery creates a new <div> element and sets the innerHTML property of the element to the HTML snippet that was passed in. When the parameter has a single tag (with optional closing tag or quick-closing) — <code>$( "<img />" )</code> or <code>$( "<img>" )</code>, <code>$( "<a></a>" )</code> or <code>$( "<a>" )</code> — jQuery creates the element using the native JavaScript <code>.createElement()</code> function.</p>
178
178
<p>When passing in complex HTML, some browsers may not generate a DOM that exactly replicates the HTML source provided. As mentioned, jQuery uses the browser's <code>.innerHTML</code> property to parse the passed HTML and insert it into the current document. During this process, some browsers filter out certain elements such as <code><html></code>, <code><title></code>, or <code><head></code> elements. As a result, the elements inserted may not be representative of the original string passed.</p>
179
179
<p>Filtering isn't, however, limited to these tags. For example, Internet Explorer prior to version 8 will also convert all <code>href</code> properties on links to absolute URLs, and Internet Explorer prior to version 9 will not correctly handle HTML5 elements without the addition of a separate <ahref="http://code.google.com/p/html5shiv/">compatibility layer</a>.</p>
180
180
<p>To ensure cross-platform compatibility, the snippet must be well-formed. Tags that can contain other elements should be paired with a closing tag:</p>
<p>When passing HTML to <code>jQuery()</code>, please also note that text nodes are not treated as DOM elements. With the exception of a few methods (such as <code>.content()</code>), they are generally otherwise ignored or removed. E.g:</p>
187
+
<p>When passing HTML to <code>jQuery()</code>, note that text nodes are not treated as DOM elements. With the exception of a few methods (such as <code>.content()</code>), they are generally ignored or removed. E.g:</p>
188
188
<pre><code>
189
-
var el = $( "1<br>2<br>3" ); // returns [<br>, "2", <br>]
<p>As of jQuery 1.4, the second argument to <code>jQuery()</code> can accept a plain object consisting of a superset of the properties that can be passed to the <ahref="/attr/">.attr()</a> method.</p>
194
-
<p><strong>Important:</strong> If the second argument is passed, the HTML string in the first argument must represent a a simple element with no attributes. <strong>As of jQuery 1.4</strong>, any <ahref="/category/events/">event type</a> can be passed in, and the following jQuery methods can be called: <ahref="/val/">val</a>, <ahref="/css/">css</a>, <ahref="/html/">html</a>, <ahref="/text/">text</a>, <ahref="/data/">data</a>, <ahref="/width/">width</a>, <ahref="/height/">height</a>, or <ahref="/offset/">offset</a>.</p>
192
+
<p>This behavior is expected. <strong>As of jQuery 1.9.0</strong> (and unless using the <ahref="https://github.com/jquery/jquery-migrate/#readme">jQuery Migrate plugin</a>), <code>jQuery()</code> requires the HTML string to start with a <code><</code> (i.e text nodes cannot appear at the front of the HTML string).</p>
193
+
<p><strong>As of jQuery 1.4</strong>, the second argument to <code>jQuery()</code> can accept a plain object consisting of a superset of the properties that can be passed to the <ahref="/attr/">.attr()</a> method.</p>
194
+
<p><strong>Important:</strong> If the second argument is passed, the HTML string in the first argument must represent a simple element with no attributes. <strong>As of jQuery 1.4</strong>, any <ahref="/category/events/">event type</a> can be passed in, and the following jQuery methods can be called: <ahref="/val/">val</a>, <ahref="/css/">css</a>, <ahref="/html/">html</a>, <ahref="/text/">text</a>, <ahref="/data/">data</a>, <ahref="/width/">width</a>, <ahref="/height/">height</a>, or <ahref="/offset/">offset</a>.</p>
195
195
<p><strong>As of jQuery 1.8</strong>, any jQuery instance method (a method of <code>jQuery.fn</code>) can be used as a property of the object passed to the second parameter:</p>
0 commit comments