From caad7f814e2cade14e5ccdf62a54b3ffce5ddb4b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B6rn=20Zaefferer?= Date: Wed, 10 Jan 2007 09:53:18 +0000 Subject: [PATCH] Fixed add to also create HTML on-the-fly by using jQuery() instead of jQuery.find() --- src/jquery/coreTest.js | 4 ++++ src/jquery/jquery.js | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/jquery/coreTest.js b/src/jquery/coreTest.js index 1c81e0808..e587c3a0e 100644 --- a/src/jquery/coreTest.js +++ b/src/jquery/coreTest.js @@ -35,6 +35,10 @@ test("add(String|Element|Array)", function() { var x = $([]).add($("

xxx

")).add($("

xxx

")); ok( x[0].id == "x1", "Check on-the-fly element1" ); ok( x[1].id == "x2", "Check on-the-fly element2" ); + + var x = $([]).add("

xxx

").add("

xxx

"); + ok( x[0].id == "x1", "Check on-the-fly element1" ); + ok( x[1].id == "x2", "Check on-the-fly element2" ); }); test("each(Function)", function() { diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 0aac02620..0f712afdf 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -930,6 +930,19 @@ jQuery.fn = jQuery.prototype = { * @param String expr An expression whose matched elements are added * @cat DOM/Traversing */ + + /** + * Adds the on the fly created elements to the jQuery object. + * + * @example $("p").add("Again") + * @before

Hello

+ * @result [

Hello

, Again ] + * + * @name add + * @type jQuery + * @param String html A string of HTML to create on the fly. + * @cat DOM/Traversing + */ /** * Adds one or more Elements to the set of matched elements. @@ -952,7 +965,7 @@ jQuery.fn = jQuery.prototype = { add: function(t) { return this.set( jQuery.merge( this.get(), - typeof t == "string" ? jQuery.find(t) : t ) + typeof t == "string" ? jQuery(t).get() : t ) ); }, -- 2.39.5