1 var isSimple = /^.[^:#\[\.,]*$/,
2 rneedsContext = jQuery.expr.match.needsContext,
3 // methods guaranteed to produce a unique set when starting from a unique set
12 find: function( selector ) {
18 if ( typeof selector !== "string" ) {
19 return this.pushStack( jQuery( selector ).filter(function() {
20 for ( i = 0; i < len; i++ ) {
21 if ( jQuery.contains( self[ i ], this ) ) {
28 for ( i = 0; i < len; i++ ) {
29 jQuery.find( selector, self[ i ], ret );
32 // Needed because $( selector, context ) becomes $( context ).find( selector )
33 ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
34 ret.selector = this.selector ? this.selector + " " + selector : selector;
38 has: function( target ) {
39 var targets = jQuery( target, this ),
42 return this.filter(function() {
44 for ( ; i < l; i++ ) {
45 if ( jQuery.contains( this, targets[i] ) ) {
52 not: function( selector ) {
53 return this.pushStack( winnow(this, selector || [], true) );
56 filter: function( selector ) {
57 return this.pushStack( winnow(this, selector || [], false) );
60 is: function( selector ) {
64 // If this is a positional/relative selector, check membership in the returned set
65 // so $("p:first").is("p:last") won't return true for a doc with two "p".
66 typeof selector === "string" && rneedsContext.test( selector ) ?
73 closest: function( selectors, context ) {
78 pos = ( rneedsContext.test( selectors ) || typeof selectors !== "string" ) ?
79 jQuery( selectors, context || this.context ) :
82 for ( ; i < l; i++ ) {
83 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
84 // Always skip document fragments
85 if ( cur.nodeType < 11 && (pos ?
88 // Don't pass non-elements to Sizzle
90 jQuery.find.matchesSelector(cur, selectors)) ) {
92 cur = matched.push( cur );
98 return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
101 // Determine the position of an element within
102 // the matched set of elements
103 index: function( elem ) {
105 // No argument, return index in parent
107 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
111 if ( typeof elem === "string" ) {
112 return core_indexOf.call( jQuery( elem ), this[ 0 ] );
115 // Locate the position of the desired element
116 return core_indexOf.call( this,
118 // If it receives a jQuery object, the first element is used
119 elem.jquery ? elem[ 0 ] : elem
123 add: function( selector, context ) {
124 var set = typeof selector === "string" ?
125 jQuery( selector, context ) :
126 jQuery.makeArray( selector && selector.nodeType ? [ selector ] : selector ),
127 all = jQuery.merge( this.get(), set );
129 return this.pushStack( jQuery.unique(all) );
132 addBack: function( selector ) {
133 return this.add( selector == null ?
134 this.prevObject : this.prevObject.filter(selector)
139 function sibling( cur, dir ) {
140 while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
146 parent: function( elem ) {
147 var parent = elem.parentNode;
148 return parent && parent.nodeType !== 11 ? parent : null;
150 parents: function( elem ) {
151 return jQuery.dir( elem, "parentNode" );
153 parentsUntil: function( elem, i, until ) {
154 return jQuery.dir( elem, "parentNode", until );
156 next: function( elem ) {
157 return sibling( elem, "nextSibling" );
159 prev: function( elem ) {
160 return sibling( elem, "previousSibling" );
162 nextAll: function( elem ) {
163 return jQuery.dir( elem, "nextSibling" );
165 prevAll: function( elem ) {
166 return jQuery.dir( elem, "previousSibling" );
168 nextUntil: function( elem, i, until ) {
169 return jQuery.dir( elem, "nextSibling", until );
171 prevUntil: function( elem, i, until ) {
172 return jQuery.dir( elem, "previousSibling", until );
174 siblings: function( elem ) {
175 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
177 children: function( elem ) {
178 return jQuery.sibling( elem.firstChild );
180 contents: function( elem ) {
181 return jQuery.nodeName( elem, "iframe" ) ?
182 elem.contentDocument || elem.contentWindow.document :
183 jQuery.merge( [], elem.childNodes );
185 }, function( name, fn ) {
186 jQuery.fn[ name ] = function( until, selector ) {
187 var matched = jQuery.map( this, fn, until );
189 if ( name.slice( -5 ) !== "Until" ) {
193 if ( selector && typeof selector === "string" ) {
194 matched = jQuery.filter( selector, matched );
197 if ( this.length > 1 ) {
199 if ( !guaranteedUnique[ name ] ) {
200 jQuery.unique( matched );
203 // Reverse order for parents* and prev*
204 if ( name[ 0 ] === "p" ) {
209 return this.pushStack( matched );
214 filter: function( expr, elems, not ) {
215 var elem = elems[ 0 ];
218 expr = ":not(" + expr + ")";
221 return elems.length === 1 && elem.nodeType === 1 ?
222 jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
223 jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
224 return elem.nodeType === 1;
228 dir: function( elem, dir, until ) {
230 truncate = until !== undefined;
232 while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
233 if ( elem.nodeType === 1 ) {
234 if ( truncate && jQuery( elem ).is( until ) ) {
237 matched.push( elem );
243 sibling: function( n, elem ) {
246 for ( ; n; n = n.nextSibling ) {
247 if ( n.nodeType === 1 && n !== elem ) {
256 // Implement the identical functionality for filter and not
257 function winnow( elements, qualifier, not ) {
258 if ( jQuery.isFunction( qualifier ) ) {
259 return jQuery.grep( elements, function( elem, i ) {
261 return !!qualifier.call( elem, i, elem ) !== not;
266 if ( qualifier.nodeType ) {
267 return jQuery.grep( elements, function( elem ) {
268 return ( elem === qualifier ) !== not;
273 if ( typeof qualifier === "string" ) {
274 if ( isSimple.test( qualifier ) ) {
275 return jQuery.filter( qualifier, elements, not );
278 qualifier = jQuery.filter( qualifier, elements );
281 return jQuery.grep( elements, function( elem ) {
282 return ( core_indexOf.call( qualifier, elem ) >= 0 ) !== not;