Make .attr(name, null) equivalent to removeAttr(name). (Was roughly this before ...
[jquery.git] / src / attributes.js
index 608b8e3..ec4841b 100644 (file)
@@ -164,8 +164,9 @@ jQuery.fn.extend({
                                                var option = options[ i ];
 
                                                // Don't return options that are disabled or in a disabled optgroup
-                                               if ( option.selected && option.getAttribute("disabled") === null && 
+                                               if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) && 
                                                                (!option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" )) ) {
+
                                                        // Get the specific value for the option
                                                        value = jQuery(option).val();
 
@@ -294,7 +295,14 @@ jQuery.extend({
                                                jQuery.error( "type property can't be changed" );
                                        }
 
-                                       elem[ name ] = value;
+                                       if ( value === null ) {
+                                               if ( elem.nodeType === 1 ) {
+                                                       elem.removeAttribute( name );
+                                               }
+
+                                       } else {
+                                               elem[ name ] = value;
+                                       }
                                }
 
                                // browsers index elements by id/name on forms, give priority to attributes.
@@ -332,7 +340,7 @@ jQuery.extend({
 
                        // Ensure that missing attributes return undefined
                        // Blackberry 4.7 returns "" from getAttribute #6938
-                       if ( !elem.attributes[ name ] && !elem.hasAttribute( name ) ) {
+                       if ( !elem.attributes[ name ] && (elem.hasAttribute && !elem.hasAttribute( name )) ) {
                                return undefined;
                        }