Skip to content

Commit cff5323

Browse files
committed
jquery core: closes jquery#2930. Normalizing attr() to return undefined, even when getting DOM attributes.
1 parent 7f27816 commit cff5323

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/core.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ jQuery.extend({
10601060
elem.parentNode.selectedIndex;
10611061

10621062
// If applicable, access the attribute via the DOM 0 way
1063-
if ( notxml && !special && name in elem ) {
1063+
if ( name in elem && notxml && !special ) {
10641064
if ( set ){
10651065
// We can't allow the type property to be changed (since it causes problems in IE)
10661066
if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
@@ -1083,11 +1083,13 @@ jQuery.extend({
10831083
// convert the value to a string (all browsers do this but IE) see #1070
10841084
elem.setAttribute( name, "" + value );
10851085

1086-
if ( msie && special && notxml )
1087-
return elem.getAttribute( name, 2 );
1088-
1089-
return elem.getAttribute( name );
1086+
var attr = msie && notxml && special
1087+
// Some attributes require a special call on IE
1088+
? elem.getAttribute( name, 2 )
1089+
: elem.getAttribute( name );
10901090

1091+
// Non-existent attributes return null, we normalize to undefined
1092+
return attr === null ? undefined : attr;
10911093
}
10921094

10931095
// elem is actually elem.style ... set the style

0 commit comments

Comments
 (0)