Skip to content

Commit 578de69

Browse files
committed
html: warn about using .html() to insert scripts
Fixes jquerygh-618 Closes jquerygh-675
1 parent 46bdad0 commit 578de69

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

entries/html.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ $( "div.demo-container" ).html(function() {
119119
</code></pre>
120120
<p>Given a document with six paragraphs, this example will set the HTML of <code>&lt;div class="demo-container"&gt;</code> to <code>&lt;p&gt;All new content for &lt;em&gt;6 paragraphs!&lt;/em&gt;&lt;/p&gt;</code>.</p>
121121
<p>This method uses the browser's <code>innerHTML</code> property. Some browsers may not generate a DOM that exactly replicates the HTML source provided. For example, Internet Explorer prior to version 8 will 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 <a href="http://code.google.com/p/html5shiv/">compatibility layer</a>.</p>
122+
<p>To set the content of a <code>&lt;script&gt;</code> element, which does not contain HTML, use the <a href="/text"><code>.text()</code></a> method and not <code>.html()</code>.</p>
122123
<p><strong>Note:</strong> In Internet Explorer up to and including version 9, setting the text content of an HTML element may corrupt the text nodes of its children that are being removed from the document as a result of the operation. If you are keeping references to these DOM elements and need them to be unchanged, use <code>.empty().html( string )</code> instead of <code>.html(string)</code> so that the elements are removed from the document before the new string is assigned to the element.</p>
123124
</longdesc>
124125
<example>

0 commit comments

Comments
 (0)