Make sure that the contents of the element is still in place when html(Function)...
authorJohn Resig <jeresig@gmail.com>
Tue, 28 Sep 2010 16:50:44 +0000 (09:50 -0700)
committerJohn Resig <jeresig@gmail.com>
Tue, 28 Sep 2010 16:50:44 +0000 (09:50 -0700)
src/manipulation.js
test/unit/manipulation.js

index 00e3120..325f303 100644 (file)
@@ -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 {
index 2fc6f18..7b4f4d1 100644 (file)
@@ -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( !/</.test( jQuery("#main").html() ), "Replace html with text." );
+       ok( jQuery("#main").html().length > 0, "Make sure text exists." );
 });
 
 test("html(Function) with incoming value", function() {