From 0368606c081fd15dfbcd8509734ef63c58a6b008 Mon Sep 17 00:00:00 2001 From: John Resig Date: Tue, 28 Sep 2010 09:50:44 -0700 Subject: [PATCH] Make sure that the contents of the element is still in place when html(Function) is called. Fixes #6733. --- src/manipulation.js | 6 ++---- test/unit/manipulation.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) 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() { -- 1.7.10.4