Skip to content
Permalink
Browse files

Make sure that missing attributes return undefined in Blackberry 4.7.…

… Fixes #6938.
  • Loading branch information
jeresig committed Aug 24, 2010
1 parent 1bdcffb commit cb40495b21bcb7802f3ab6ae0f837f2bf5b385ed
Showing with 6 additions and 0 deletions.
  1. +6 −0 src/attributes.js
@@ -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.

Copy link
@jitter

jitter Sep 27, 2010

Contributor

This change breaks some attr() calls in IE6/IE7 as they don't seem to support the hasAttribute call.

Example this test from test/unit/attributes.js:
equals( jQuery('#area1').attr('maxLength'), '30', 'Check for maxLength attribute' );

For textarea the casing of maxLength in IE6/IE7 is all lowercase. As the casing of name is different from the internal casing of IE6/7 for the attribute we get a Object doesn't support this property or method exception when the !elem.hasAttribute( name ) part is evaluated.

This comment has been minimized.

Copy link
@jeresig

jeresig Sep 27, 2010

Author Member

I've landed a fix for this here: a384d84 Thankfully we already had a fallback in place which allowed it to continue working. There are some bugs with .val() in IE now that I'm checking in to - not sure if it's related to this, or not. Thanks again!

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

@jdalton

This comment has been minimized.

Copy link
Member

@jdalton jdalton replied Aug 24, 2010

That means it follows spec
getAttribute shouldn't be used as a hasAttribute alternative and just over-complicates things when attempted.

@jzaefferer

This comment has been minimized.

Copy link
Member

@jzaefferer jzaefferer replied Aug 24, 2010

Then we can be happy that other browsers don't follow the spec, and hope for a fix to the spec instead.

@jdalton

This comment has been minimized.

Copy link
Member

@jdalton jdalton replied Aug 24, 2010

Or yall could return an empty string "" if it gets a null value :D

@jzaefferer

This comment has been minimized.

Copy link
Member

@jzaefferer jzaefferer replied Aug 24, 2010

And then add hasAttr to jQuery?

@jdalton

This comment has been minimized.

Copy link
Member

@jdalton jdalton replied Aug 24, 2010

Sure. Why not? Lets go for the gold and get a decent attribute API for jQuery.

@jzaefferer

This comment has been minimized.

Copy link
Member

@jzaefferer jzaefferer replied Aug 24, 2010

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...?

@jdalton

This comment has been minimized.

Copy link
Member

@jdalton jdalton replied Aug 24, 2010

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.

Please sign in to comment.
You can’t perform that action at this time.