Fixed add to also create HTML on-the-fly by using jQuery() instead of jQuery.find()

This commit is contained in:
Jörn Zaefferer 2007-01-10 09:53:18 +00:00
parent a5f9108a21
commit caad7f814e
2 changed files with 18 additions and 1 deletions

View file

@ -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() {

15
src/jquery/jquery.js vendored
View file

@ -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 )
);
},