Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 d638aa9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/manipulation.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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() ] ) {

Expand Down
10 changes: 9 additions & 1 deletion test/unit/manipulation.js
Expand Up @@ -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" );
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit d638aa9

Please sign in to comment.