diff options
author | timmywil <tim.willison@thisismedium.com> | 2011-03-10 18:34:15 -0500 |
---|---|---|
committer | timmywil <tim.willison@thisismedium.com> | 2011-04-03 19:13:38 -0400 |
commit | 607210e01068224ac613558c0a314ad4a8fba247 (patch) | |
tree | a56dc7f45dbf09ee3aec8cc973bae999bea2b073 /src/attributes.js | |
parent | 5eecb13fa3391870e904548f03d8a509117984f3 (diff) | |
download | jquery-607210e01068224ac613558c0a314ad4a8fba247.tar.gz jquery-607210e01068224ac613558c0a314ad4a8fba247.zip |
Speed up hasAttr a little
Diffstat (limited to 'src/attributes.js')
-rw-r--r-- | src/attributes.js | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/attributes.js b/src/attributes.js index 8de5cf80c..83d02e212 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -334,18 +334,20 @@ jQuery.extend({ }, hasAttr: function( elem, name ) { - var inAttrs, attrs = elem.attributes; - - if ( elem.hasAttribute ) { - return elem.hasAttribute( name ); - } else { - // Browsers do not understand the associative indexes, look for the name in elem.attributes.name - for ( var i = 0, l = attrs.length; i < l; i++ ) { - if ( attrs[i]["name"] === name ) { - return true; + + return elem.hasAttribute ? + elem.hasAttribute( name ) : + (function() { + // Some browsers do not understand the associative indexes + // Look for the name in elem.attributes.name + var attrs = elem.attributes, i = 0, len = attrs.length; + for ( ; i < len; i++ ) { + if ( attrs[i]["name"] === name ) { + return true; + } } - } - } + return false; + })(); }, attrHooks: { |