Fixing getting/setting classes and makeArray(RegExp) for Blackberry 4.7. Fixes #6930...
[jquery.git] / src / attributes.js
index 004c6b3..1278ff8 100644 (file)
@@ -9,7 +9,7 @@ var rclass = /[\n\t]/g,
 
 jQuery.fn.extend({
        attr: function( name, value ) {
-               return access( this, name, value, true, jQuery.attr );
+               return jQuery.access( this, name, value, true, jQuery.attr );
        },
 
        removeAttr: function( name, fn ) {
@@ -40,12 +40,13 @@ jQuery.fn.extend({
                                                elem.className = value;
 
                                        } else {
-                                               var className = " " + elem.className + " ";
+                                               var className = " " + elem.className + " ", setClass = elem.className;
                                                for ( var c = 0, cl = classNames.length; c < cl; c++ ) {
                                                        if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) {
-                                                               elem.className += " " + classNames[c];
+                                                               setClass += " " + classNames[c];
                                                        }
                                                }
+                                               elem.className = jQuery.trim( setClass );
                                        }
                                }
                        }
@@ -74,7 +75,7 @@ jQuery.fn.extend({
                                                for ( var c = 0, cl = classNames.length; c < cl; c++ ) {
                                                        className = className.replace(" " + classNames[c] + " ", " ");
                                                }
-                                               elem.className = className.substring(1, className.length - 1);
+                                               elem.className = jQuery.trim( className );
 
                                        } else {
                                                elem.className = "";
@@ -277,11 +278,12 @@ jQuery.extend({
                        }
 
                        // If applicable, access the attribute via the DOM 0 way
-                       if ( name in elem && notxml && !special ) {
+                       // 'in' checks fail in Blackberry 4.7 #6931
+                       if ( (name in elem || elem[ name ] !== undefined) && notxml && !special ) {
                                if ( set ) {
                                        // We can't allow the type property to be changed (since it causes problems in IE)
                                        if ( name === "type" && rtype.test( elem.nodeName ) && elem.parentNode ) {
-                                               throw "type property can't be changed";
+                                               jQuery.error( "type property can't be changed" );
                                        }
 
                                        elem[ name ] = value;
@@ -330,7 +332,7 @@ jQuery.extend({
                }
 
                // elem is actually elem.style ... set the style
-               // Using attr for specific style information is now deprecated. Use style insead.
+               // Using attr for specific style information is now deprecated. Use style instead.
                return jQuery.style( elem, name, value );
        }
 });