Skip to content

Commit

Permalink
Fix #12048. Set attributes for XML fragments. Close jquerygh-965.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sai Wong authored and dmethvin committed Oct 20, 2012
1 parent 144b8bf commit 2b0e720
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ if ( !getSetAttribute ) {
// Set the existing or create a new attribute node
var ret = elem.getAttributeNode( name );
if ( !ret ) {
ret = document.createAttribute( name );
ret = elem.ownerDocument.createAttribute( name );
elem.setAttributeNode( ret );
}
return ( ret.value = value + "" );
Expand Down
1 change: 1 addition & 0 deletions test/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"testIframe": true,
"testIframeWithCallback": true,
"createDashboardXML": true,
"createXMLFragment": true,
"moduleTeardown": true,
"testFoo": true,
"foobar": true,
Expand Down
15 changes: 15 additions & 0 deletions test/data/testinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ var createWithFriesXML = function() {
return jQuery.parseXML(string);
};

var createXMLFragment = function() {
var xml, frag;
if ( window.ActiveXObject ) {
xml = new ActiveXObject("msxml2.domdocument");
} else {
xml = document.implementation.createDocument( "", "", null );
}

if ( xml ) {
frag = xml.createElement("data");
}

return frag;
};

var fireNative;
if ( document.createEvent ) {
fireNative = function( node, type ) {
Expand Down
11 changes: 11 additions & 0 deletions test/unit/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,17 @@ test( "attr(String, Object) - Loaded via XML document", function() {
equal( titles[ 1 ], "Users", "attr() in XML context: Check second title" );
});

test( "attr(String, Object) - Loaded via XML fragment", function() {
expect( 2 );
var frag = createXMLFragment(),
$frag = jQuery( frag );

$frag.attr( "test", "some value" );
equal( $frag.attr("test"), "some value", "set attribute" );
$frag.attr( "test", null );
equal( $frag.attr("test"), undefined, "remove attribute" );
});

test( "attr('tabindex')", function() {
expect( 8 );

Expand Down

0 comments on commit 2b0e720

Please sign in to comment.