]> source.dussan.org Git - jquery.git/commitdiff
Speed up hasAttr a little
authortimmywil <tim.willison@thisismedium.com>
Thu, 10 Mar 2011 23:34:15 +0000 (18:34 -0500)
committertimmywil <tim.willison@thisismedium.com>
Sun, 3 Apr 2011 23:13:38 +0000 (19:13 -0400)
src/attributes.js

index 8de5cf80c2c05f248ff32870a197324db858c562..83d02e21221e356e75e877879934d83eb2c9d4a5 100644 (file)
@@ -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: {