diff options
author | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2007-01-10 09:53:18 +0000 |
---|---|---|
committer | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2007-01-10 09:53:18 +0000 |
commit | caad7f814e2cade14e5ccdf62a54b3ffce5ddb4b (patch) | |
tree | 775d2fecad1330d3b91d6d60440deb61e99722fd /src | |
parent | a5f9108a2109b2ed5778af860b0928d8e6b0fdd2 (diff) | |
download | jquery-caad7f814e2cade14e5ccdf62a54b3ffce5ddb4b.tar.gz jquery-caad7f814e2cade14e5ccdf62a54b3ffce5ddb4b.zip |
Fixed add to also create HTML on-the-fly by using jQuery() instead of jQuery.find()
Diffstat (limited to 'src')
-rw-r--r-- | src/jquery/coreTest.js | 4 | ||||
-rw-r--r-- | src/jquery/jquery.js | 15 |
2 files changed, 18 insertions, 1 deletions
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($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
ok( x[0].id == "x1", "Check on-the-fly element1" );
ok( x[1].id == "x2", "Check on-the-fly element2" );
+
+ var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
+ 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("<span>Again</span>") + * @before <p>Hello</p> + * @result [ <p>Hello</p>, <span>Again</span> ] + * + * @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 ) ); }, |