MCPcopy Index your code
hub / github.com/jquery/jquery / find

Function find

dist-module/jquery.factory.module.js:1165–1290  ·  view source on GitHub ↗
( selector, context, results, seed )

Source from the content-addressed store, hash-verified

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

Callers 3

jQueryFactoryWrapperFunction · 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