( selector, context, results, seed )
| 803 | } |
| 804 | |
| 805 | function find( selector, context, results, seed ) { |
| 806 | var m, i, elem, nid, match, groups, newSelector, |
| 807 | newContext = context && context.ownerDocument, |
| 808 | |
| 809 | // nodeType defaults to 9, since context defaults to document |
| 810 | nodeType = context ? context.nodeType : 9; |
| 811 | |
| 812 | results = results || []; |
| 813 | |
| 814 | // Return early from calls with invalid selector or context |
| 815 | if ( typeof selector !== "string" || !selector || |
| 816 | nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) { |
| 817 | |
| 818 | return results; |
| 819 | } |
| 820 | |
| 821 | // Try to shortcut find operations (as opposed to filters) in HTML documents |
| 822 | if ( !seed ) { |
| 823 | setDocument( context ); |
| 824 | context = context || document; |
| 825 | |
| 826 | if ( documentIsHTML ) { |
| 827 | |
| 828 | // If the selector is sufficiently simple, try using a "get*By*" DOM method |
| 829 | // (excepting DocumentFragment context, where the methods don't exist) |
| 830 | if ( nodeType !== 11 && ( match = rquickExpr.exec( selector ) ) ) { |
| 831 | |
| 832 | // ID selector |
| 833 | if ( ( m = match[ 1 ] ) ) { |
| 834 | |
| 835 | // Document context |
| 836 | if ( nodeType === 9 ) { |
| 837 | if ( ( elem = context.getElementById( m ) ) ) { |
| 838 | |
| 839 | // Support: IE 9 only |
| 840 | // getElementById can match elements by name instead of ID |
| 841 | if ( elem.id === m ) { |
| 842 | push.call( results, elem ); |
| 843 | return results; |
| 844 | } |
| 845 | } else { |
| 846 | return results; |
| 847 | } |
| 848 | |
| 849 | // Element context |
| 850 | } else { |
| 851 | |
| 852 | // Support: IE 9 only |
| 853 | // getElementById can match elements by name instead of ID |
| 854 | if ( newContext && ( elem = newContext.getElementById( m ) ) && |
| 855 | find.contains( context, elem ) && |
| 856 | elem.id === m ) { |
| 857 | |
| 858 | push.call( results, elem ); |
| 859 | return results; |
| 860 | } |
| 861 | } |
| 862 |
no test coverage detected