X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fattributes.js;h=147c353f4219a14cce5a9da3674818fef583b18f;hb=b03416954d8033e641bd658fb18631699db6cc51;hp=a76695b661d16c9aa4077182a3ead23544a17696;hpb=2c4b20809e5d32e916c479c9b63a6b7528c880ce;p=jquery.git diff --git a/src/attributes.js b/src/attributes.js index a76695b..147c353 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -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,10 +210,15 @@ 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 += ""; + } else if ( jQuery.isArray(val) ) { + val = jQuery.map(val, function (value) { + return value == null ? "" : value + ""; + }); } if ( jQuery.isArray(val) && rradiocheck.test( this.type ) ) { @@ -293,7 +299,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. @@ -331,7 +344,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; }