MCPcopy Create free account
hub / github.com/components/jquery / find

Function find

jquery.js:1174–1299  ·  view source on GitHub ↗
( selector, context, results, seed )

Source from the content-addressed store, hash-verified

1172 );
1173
1174function find( selector, context, results, seed ) {
1175 var m, i, elem, nid, match, groups, newSelector,
1176 newContext = context && context.ownerDocument,
1177
1178 // nodeType defaults to 9, since context defaults to document
1179 nodeType = context ? context.nodeType : 9;
1180
1181 results = results || [];
1182
1183 // Return early from calls with invalid selector or context
1184 if ( typeof selector !== "string" || !selector ||
1185 nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
1186
1187 return results;
1188 }
1189
1190 // Try to shortcut find operations (as opposed to filters) in HTML documents
1191 if ( !seed ) {
1192 setDocument( context );
1193 context = context || document;
1194
1195 if ( documentIsHTML ) {
1196
1197 // If the selector is sufficiently simple, try using a "get*By*" DOM method
1198 // (excepting DocumentFragment context, where the methods don't exist)
1199 if ( nodeType !== 11 && ( match = rquickExpr$1.exec( selector ) ) ) {
1200
1201 // ID selector
1202 if ( ( m = match[ 1 ] ) ) {
1203
1204 // Document context
1205 if ( nodeType === 9 ) {
1206 if ( ( elem = context.getElementById( m ) ) ) {
1207 push.call( results, elem );
1208 }
1209 return results;
1210
1211 // Element context
1212 } else {
1213 if ( newContext && ( elem = newContext.getElementById( m ) ) &&
1214 jQuery.contains( context, elem ) ) {
1215
1216 push.call( results, elem );
1217 return results;
1218 }
1219 }
1220
1221 // Type selector
1222 } else if ( match[ 2 ] ) {
1223 push.apply( results, context.getElementsByTagName( selector ) );
1224 return results;
1225
1226 // Class selector
1227 } else if ( ( m = match[ 3 ] ) && context.getElementsByClassName ) {
1228 push.apply( results, context.getElementsByClassName( m ) );
1229 return results;
1230 }
1231 }

Callers 3

jquery.jsFile · 0.70
multipleContextsFunction · 0.70
selectFunction · 0.70

Calls 5

setDocumentFunction · 0.70
testContextFunction · 0.70
tokenizeFunction · 0.70
toSelectorFunction · 0.70
selectFunction · 0.70

Tested by

no test coverage detected