2 find: function( selector ) {
3 var ret = this.pushStack( "", "find", selector ), length = 0;
5 for ( var i = 0, l = this.length; i < l; i++ ) {
7 jQuery.find( selector, this[i], ret );
10 // Make sure that the results are unique
11 for ( var n = length; n < ret.length; n++ ) {
12 for ( var r = 0; r < length; r++ ) {
13 if ( ret[r] === ret[n] ) {
25 filter: function( selector ) {
26 return this.pushStack(
27 jQuery.isFunction( selector ) &&
28 jQuery.grep(this, function(elem, i){
29 return selector.call( elem, i );
32 jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
33 return elem.nodeType === 1;
34 }) ), "filter", selector );
37 closest: function( selector ) {
38 var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null,
41 return this.map(function(){
43 while ( cur && cur.ownerDocument ) {
44 if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) ) {
45 jQuery.data(cur, "closest", closer);
54 not: function( selector ) {
55 if ( typeof selector === "string" )
56 // test special case where just one selector is passed in
57 if ( isSimple.test( selector ) )
58 return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
60 selector = jQuery.multiFilter( selector, this );
62 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
63 return this.filter(function() {
64 return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
68 add: function( selector ) {
69 return this.pushStack( jQuery.unique( jQuery.merge(
71 typeof selector === "string" ?
73 jQuery.makeArray( selector )
78 return this.slice( i, +i + 1 );
82 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
83 "slice", Array.prototype.slice.call(arguments).join(",") );
86 map: function( callback ) {
87 return this.pushStack( jQuery.map(this, function(elem, i){
88 return callback.call( elem, i, elem );
93 return this.add( this.prevObject );
97 return this.prevObject || jQuery(null);
102 parent: function(elem){return elem.parentNode;},
103 parents: function(elem){return jQuery.dir(elem,"parentNode");},
104 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
105 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
106 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
107 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
108 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
109 children: function(elem){return jQuery.sibling(elem.firstChild);},
110 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
111 }, function(name, fn){
112 jQuery.fn[ name ] = function( selector ) {
113 var ret = jQuery.map( this, fn );
115 if ( selector && typeof selector == "string" )
116 ret = jQuery.multiFilter( selector, ret );
118 return this.pushStack( jQuery.unique( ret ), name, selector );