aboutsummaryrefslogtreecommitdiffstats
path: root/src/jquery
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2007-09-04 04:44:54 +0000
committerJohn Resig <jeresig@gmail.com>2007-09-04 04:44:54 +0000
commitf28f199dc0a353135ef8b9afa2f3d25c6ffd2c75 (patch)
tree69a8d43069aa367f2953b11d780bfe2f57c558b6 /src/jquery
parentd259ec1a93ea087d76c02009eccaa42786f737bb (diff)
downloadjquery-f28f199dc0a353135ef8b9afa2f3d25c6ffd2c75.tar.gz
jquery-f28f199dc0a353135ef8b9afa2f3d25c6ffd2c75.zip
Added support for the new .andSelf() method. This method combines the previous two matched sets on the stack into a single stack.
For example: $("#foo").parent(); // => [ #bar ] $("#foo").parent().andSelf(); // => [ #bar, #foo ]
Diffstat (limited to 'src/jquery')
-rw-r--r--src/jquery/coreTest.js8
-rw-r--r--src/jquery/jquery.js8
2 files changed, 14 insertions, 2 deletions
diff --git a/src/jquery/coreTest.js b/src/jquery/coreTest.js
index 18fed649e..d0fc9d25e 100644
--- a/src/jquery/coreTest.js
+++ b/src/jquery/coreTest.js
@@ -849,6 +849,14 @@ test("not()", function() {
isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
});
+test("andSelf()", function() {
+ expect(4);
+ isSet( $("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
+ isSet( $("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
+ isSet( $("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" );
+ isSet( $("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
+});
+
test("siblings([String])", function() {
expect(5);
isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js
index 038323adb..9e59f9dad 100644
--- a/src/jquery/jquery.js
+++ b/src/jquery/jquery.js
@@ -325,13 +325,17 @@ jQuery.fn = jQuery.prototype = {
return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
},
- map: function(fn){
+ map: function(fn) {
return this.pushStack(jQuery.map( this, function(elem,i){
return fn.call( elem, i, elem );
}));
},
+
+ andSelf: function() {
+ return this.add( this.prevObject );
+ },
- domManip: function(args, table, dir, fn){
+ domManip: function(args, table, dir, fn) {
var clone = this.length > 1, a;
return this.each(function(){