… Fixes #6938.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -325,6 +325,12 @@ jQuery.extend({ | ||
elem.setAttribute( name, "" + value ); | ||
} | ||
|
||
// Ensure that missing attributes return undefined | ||
// Blackberry 4.7 returns "" from getAttribute #6938 | ||
if ( !elem.attributes[ name ] && !elem.hasAttribute( name ) ) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jeresig
Author
Member
|
||
return undefined; | ||
} | ||
|
||
var attr = !jQuery.support.hrefNormalized && notxml && special ? | ||
// Some attributes require a special call on IE | ||
elem.getAttribute( name, 2 ) : | ||
7 comments
on commit cb40495
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That means it follows spec
getAttribute
shouldn't be used as a hasAttribute
alternative and just over-complicates things when attempted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we can be happy that other browsers don't follow the spec, and hope for a fix to the spec instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or yall could return an empty string ""
if it gets a null value :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then add hasAttr to jQuery?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Why not? Lets go for the gold and get a decent attribute API for jQuery.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is adding an additional method gold, while returning undefined for undefined attributes already works?
Would you prefer to do hasProperty(myObject.someProperty) && myObject.someProperty... instead of just myObject.someProperty && myObject.someProperty...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow you. I guess you aren't a fan.
As long as node.hasAttribute()
, and attrNode.specified
as a fallback, are used, even internally, it will help reduce the likelihood of other errors.
This change breaks some
attr()
calls in IE6/IE7 as they don't seem to support thehasAttribute
call.Example this test from test/unit/attributes.js:
equals( jQuery('#area1').attr('maxLength'), '30', 'Check for maxLength attribute' );
For
textarea
the casing ofmaxLength
in IE6/IE7 is all lowercase. As the casing ofname
is different from the internal casing of IE6/7 for the attribute we get aObject doesn't support this property or method
exception when the!elem.hasAttribute( name )
part is evaluated.