Fix attr() problems in IE with attribute nodes. Followup to commit b50f41a2
.
IE can't add properties on an attribute-node element, thus we handle it like text-/comment-nodes.
This commit is contained in:
parent
8943b427f6
commit
cc9dbd06e5
|
@ -272,8 +272,8 @@ jQuery.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
attr: function( elem, name, value, pass ) {
|
attr: function( elem, name, value, pass ) {
|
||||||
// don't set attributes on text and comment nodes
|
// don't get/set attributes on text, comment and attribute nodes
|
||||||
if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) {
|
if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || elem.nodeType === 2 ) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,12 +146,12 @@ test("attr(String, Object)", function() {
|
||||||
commentNode = document.createComment("some comment"),
|
commentNode = document.createComment("some comment"),
|
||||||
textNode = document.createTextNode("some text"),
|
textNode = document.createTextNode("some text"),
|
||||||
obj = {};
|
obj = {};
|
||||||
jQuery.each( [document, attributeNode, obj, "#firstp"], function( i, ele ) {
|
jQuery.each( [document, obj, "#firstp"], function( i, ele ) {
|
||||||
var $ele = jQuery( ele );
|
var $ele = jQuery( ele );
|
||||||
$ele.attr( "nonexisting", "foo" );
|
$ele.attr( "nonexisting", "foo" );
|
||||||
equal( $ele.attr("nonexisting"), "foo", "attr(name, value) works correctly for non existing attributes (bug #7500)." );
|
equal( $ele.attr("nonexisting"), "foo", "attr(name, value) works correctly for non existing attributes (bug #7500)." );
|
||||||
});
|
});
|
||||||
jQuery.each( [commentNode, textNode], function( i, ele ) {
|
jQuery.each( [commentNode, textNode, attributeNode], function( i, ele ) {
|
||||||
var $ele = jQuery( ele );
|
var $ele = jQuery( ele );
|
||||||
$ele.attr( "nonexisting", "foo" );
|
$ele.attr( "nonexisting", "foo" );
|
||||||
strictEqual( $ele.attr("nonexisting"), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." );
|
strictEqual( $ele.attr("nonexisting"), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." );
|
||||||
|
@ -341,12 +341,12 @@ test("removeAttr(String)", function() {
|
||||||
//removeAttr only really removes on DOM element nodes handle all other seperatyl
|
//removeAttr only really removes on DOM element nodes handle all other seperatyl
|
||||||
strictEqual( jQuery( "#firstp" ).attr( "nonexisting", "foo" ).removeAttr( "nonexisting" )[0].nonexisting, undefined, "removeAttr works correctly on DOM element nodes" );
|
strictEqual( jQuery( "#firstp" ).attr( "nonexisting", "foo" ).removeAttr( "nonexisting" )[0].nonexisting, undefined, "removeAttr works correctly on DOM element nodes" );
|
||||||
|
|
||||||
jQuery.each( [document, attributeNode, obj], function( i, ele ) {
|
jQuery.each( [document, obj], function( i, ele ) {
|
||||||
var $ele = jQuery( ele );
|
var $ele = jQuery( ele );
|
||||||
$ele.attr( "nonexisting", "foo" ).removeAttr( "nonexisting" );
|
$ele.attr( "nonexisting", "foo" ).removeAttr( "nonexisting" );
|
||||||
strictEqual( ele.nonexisting, "", "removeAttr works correctly on non DOM element nodes (bug #7500)." );
|
strictEqual( ele.nonexisting, "", "removeAttr works correctly on non DOM element nodes (bug #7500)." );
|
||||||
});
|
});
|
||||||
jQuery.each( [commentNode, textNode], function( i, ele ) {
|
jQuery.each( [commentNode, textNode, attributeNode], function( i, ele ) {
|
||||||
$ele = jQuery( ele );
|
$ele = jQuery( ele );
|
||||||
$ele.attr( "nonexisting", "foo" ).removeAttr( "nonexisting" );
|
$ele.attr( "nonexisting", "foo" ).removeAttr( "nonexisting" );
|
||||||
strictEqual( ele.nonexisting, undefined, "removeAttr works correctly on non DOM element nodes (bug #7500)." );
|
strictEqual( ele.nonexisting, undefined, "removeAttr works correctly on non DOM element nodes (bug #7500)." );
|
||||||
|
|
Loading…
Reference in a new issue