From 4681216c4bdf25b6b146b3f952917f46079c6ef7 Mon Sep 17 00:00:00 2001 From: jeresig Date: Thu, 7 Jan 2010 09:53:16 -0500 Subject: [PATCH] Fixed some bugs relating to the setter arg change in val and html. Also optimized the code in val a bit. --- src/attributes.js | 31 +++++++++++++------------------ src/manipulation.js | 2 +- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/attributes.js b/src/attributes.js index a5a6662c..1dd70842 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -195,30 +195,25 @@ jQuery.fn.extend({ return undefined; } - // Typecast once if the value is a number - if ( typeof value === "number" ) { - value += ""; - } - - var val = value; + var isFunction = jQuery.isFunction(value); return this.each(function(i) { - var self = jQuery(this); - - if ( jQuery.isFunction(value) ) { - 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" ) { - val += ""; - } - } + var self = jQuery(this), val = value; if ( this.nodeType !== 1 ) { return; } + if ( isFunction ) { + 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" ) { + val += ""; + } + if ( jQuery.isArray(val) && rradiocheck.test( this.type ) ) { this.checked = jQuery.inArray( self.val(), val ) >= 0; @@ -226,7 +221,7 @@ jQuery.fn.extend({ var values = jQuery.makeArray(val); jQuery( "option", this ).each(function() { - this.selected = jQuery.inArray( self.val(), values ) >= 0; + this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0; }); if ( !values.length ) { diff --git a/src/manipulation.js b/src/manipulation.js index 730dfca5..081bb548 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -173,7 +173,7 @@ jQuery.fn.extend({ html: function( value ) { if ( value === undefined ) { - return this[0] ? + return this[0] && this[0].nodeType === 1 ? this[0].innerHTML.replace(rinlinejQuery, "") : null;