Skip to content
Permalink
Browse files
Fixed add to also create HTML on-the-fly by using jQuery() instead of…
… jQuery.find()
  • Loading branch information
jzaefferer committed Jan 10, 2007
1 parent a5f9108 commit caad7f814e2cade14e5ccdf62a54b3ffce5ddb4b
Showing with 18 additions and 1 deletion.
  1. +4 −0 src/jquery/coreTest.js
  2. +14 −1 src/jquery/jquery.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() {
@@ -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 )
);
},

0 comments on commit caad7f8

Please sign in to comment.