Add a feature test for options inside a disabled select. Follow-up to 157a383dae5335e...
[jquery.git] / src / attributes.js
index a76695b..dd6a3e7 100644 (file)
@@ -136,7 +136,7 @@ jQuery.fn.extend({
        },
 
        val: function( value ) {
-               if ( value === undefined ) {
+               if ( !arguments.length ) {
                        var elem = this[0];
 
                        if ( elem ) {
@@ -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.disabled && 
+                                               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();
 
@@ -209,9 +210,10 @@ jQuery.fn.extend({
                                val = value.call(this, i, self.val());
                        }
 
-                       // Typecast each time if the value is a Function and the appended
-                       // value is therefore different each time.
-                       if ( typeof val === "number" ) {
+                       // Treat null/undefined as ""; convert numbers to string
+                       if ( val == null ) {
+                               val = "";
+                       } else if ( typeof val === "number" ) {
                                val += "";
                        }
 
@@ -331,7 +333,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;
                        }