Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix #9646. Cloned nodes shouldn't affect original in IE7. Close gh-947.

  • Loading branch information...
commit 13651f296d14b2400d703d1945065c0373862eb5 1 parent 0018f77
Oleg Gaidarenko markelog authored dmethvin committed
Showing with 33 additions and 1 deletion.
  1. +9 −1 src/attributes.js
  2. +24 −0 test/unit/attributes.js
10 src/attributes.js
View
@@ -522,7 +522,15 @@ if ( !getSetAttribute ) {
ret = elem.ownerDocument.createAttribute( name );
elem.setAttributeNode( ret );
}
- return ( ret.value = value + "" );
+
+ ret.value = value += "";
+
+ // Break association with cloned elements (#9646)
+ if ( name !== "value" && value !== elem.getAttribute( name ) ) {
+ elem.setAttribute( name, value );
+ }
+
+ return value;
}
};
24 test/unit/attributes.js
View
@@ -156,6 +156,30 @@ test( "attr(String)", function() {
$form = jQuery("#form").attr( "enctype", "multipart/form-data" );
equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
+
+});
+
+test( "attr(String) on cloned elements, #9646", function() {
+ expect( 4 );
+
+ var div,
+ input = jQuery("<input name='tester' />");
+
+ input.attr("name");
+
+ strictEqual( input.clone( true ).attr( "name", "test" )[ 0 ].name, "test", "Name attribute should be changed on cloned element" );
+
+ div = jQuery("<div id='tester' />");
+ div.attr("id");
+
+ strictEqual( div.clone( true ).attr( "id", "test" )[ 0 ].id, "test", "Id attribute should be changed on cloned element" );
+
+ input = jQuery("<input value='tester' />");
+ input.attr("value");
+
+ strictEqual( input.clone( true ).attr( "value", "test" )[ 0 ].value, "test", "Value attribute should be changed on cloned element" );
+
+ strictEqual( input.clone( true ).attr( "value", 42 )[ 0 ].value, "42", "Value attribute should be changed on cloned element" );
});
test( "attr(String) in XML Files", function() {
Please sign in to comment.
Something went wrong with that request. Please try again.