Permalink
Browse files

Fixes #9646

  • Loading branch information...
1 parent e8f9151 commit 5b9a8b5a907d08efcc2bfc17eb4354aff5e01540 @markelog committed Oct 1, 2012
Showing with 31 additions and 1 deletion.
  1. +9 −1 src/attributes.js
  2. +22 −0 test/unit/attributes.js
View
@@ -530,7 +530,15 @@ if ( !getSetAttribute ) {
ret = elem.ownerDocument.createAttribute( name );
elem.setAttributeNode( ret );
}
- return ( ret.value = value + "" );
+
+ ret.value = value += "";
+
+ // #9646
+ if ( name !== "value" && value !== elem.getAttribute( name ) ) {
+ elem.setAttribute( name, value );
+ }
+
+ return value;
}
};
View
@@ -151,6 +151,28 @@ 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( 3 );
+
+ var div,
+ input = jQuery("<input name='tester' />");
+
+ input.attr("name");
@dmethvin

dmethvin Dec 12, 2012

Why are these attr gets here? We're not using the result.

@markelog

markelog Dec 12, 2012

Owner

We are not, just like in here and here.

But in order to trigger the error, we have to do that, remember?

+
+ 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" );
});
test( "attr(String) in XML Files", function() {

0 comments on commit 5b9a8b5

Please sign in to comment.