Skip to content
Permalink
Browse files

Allow more cases to use `innerHTML` in the `.html` method.

Thanks @cmcnulty for the pull and the patience!
  • Loading branch information...
dmethvin committed Sep 22, 2011
2 parents a4cdbf0 + 2746d7f commit d638aa9c6d6394db0c06431560b3d8b83cacc61c
Showing with 11 additions and 2 deletions.
  1. +2 −1 src/manipulation.js
  2. +9 −1 test/unit/manipulation.js
@@ -6,6 +6,7 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
rtagName = /<([\w:]+)/,
rtbody = /<tbody/i,
rhtml = /<|&#?\w+;/,
rnoInnerhtml = /<(?:script|style)/i,
rnocache = /<(?:script|object|embed|option|style)/i,
// checked="checked" or checked
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
@@ -217,7 +218,7 @@ jQuery.fn.extend({
null;

// See if we can take a shortcut and just use innerHTML
} else if ( typeof value === "string" && !rnocache.test( value ) &&
} else if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
(jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) &&
!wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {

@@ -991,7 +991,7 @@ test("clone() (#8070)", function () {
});

test("clone()", function() {
expect(37);
expect(40);
equals( "This is a normal link: Yahoo", jQuery("#en").text(), "Assert text for #en" );
var clone = jQuery("#yahoo").clone();
equals( "Try them out:Yahoo", jQuery("#first").append(clone).text(), "Check for clone" );
@@ -1058,6 +1058,14 @@ test("clone()", function() {
cloneEvt.remove();
divEvt.remove();

// Test both html() and clone() for <embed and <object types
div = jQuery("<div/>").html('<embed height="355" width="425" src="http://www.youtube.com/v/3KANI2dpXLw&amp;hl=en"></embed>');

clone = div.clone(true);
equals( clone.length, 1, "One element cloned" );
equals( clone.html(), div.html(), "Element contents cloned" );
equals( clone[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );

// this is technically an invalid object, but because of the special
// classid instantiation it is the only kind that IE has trouble with,
// so let's test with it too.

1 comment on commit d638aa9

@cmcnulty

This comment has been minimized.

Copy link
Contributor

commented on d638aa9 Oct 4, 2011

This should result in negligible perf changes in modern browsers ( possibly positive or negative), but improvements in oldIEs of 50% or even greater.

Perf test

Please sign in to comment.
You can’t perform that action at this time.