From: John Resig Date: Tue, 28 Sep 2010 16:50:44 +0000 (-0700) Subject: Make sure that the contents of the element is still in place when html(Function)... X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=0368606c081fd15dfbcd8509734ef63c58a6b008;hp=e3c4e5789743eecb3cbe2b626f3a5f09c616ee4b;p=jquery.git Make sure that the contents of the element is still in place when html(Function) is called. Fixes #6733. --- diff --git a/src/manipulation.js b/src/manipulation.js index 00e3120..325f303 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -248,10 +248,8 @@ jQuery.fn.extend({ } else if ( jQuery.isFunction( value ) ) { this.each(function(i){ - var self = jQuery(this), old = self.html(); - self.empty().append(function(){ - return value.call( this, i, old ); - }); + var self = jQuery(this); + self.html( value.call(this, i, self.html()) ); }); } else { diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 2fc6f18..7b4f4d1 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -955,6 +955,17 @@ test("html(String)", function() { test("html(Function)", function() { testHtml(functionReturningObj); + + expect(33); + + QUnit.reset(); + + jQuery("#main").html(function(){ + return jQuery(this).text(); + }); + + ok( !/ 0, "Make sure text exists." ); }); test("html(Function) with incoming value", function() {