// A simple way to check for HTML strings or ID strings
// (both of which we optimize for)
- quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
+ quickExpr = /^[^<]*(<[\w\W]+>)[^>]*$|^#([\w-]+)$/,
// Is it a simple selector
isSimple = /^.[^:#\[\.,]*$/,
push = Array.prototype.push,
slice = Array.prototype.slice;
-// Expose jQuery to the global object
-window.jQuery = window.$ = jQuery;
-
jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {
var match, elem, ret;
// Handle $(""), $(null), or $(undefined)
- if ( !selector ) return this;
+ if ( !selector ) {
+ return this;
+ }
+
+ // $("body"): Shortcut for quickly finding the body element
+ if ( selector === "body" && !context && document.body ) {
+ selector = document.body;
+ }
// Handle $(DOMElement)
if ( selector.nodeType ) {
// HANDLE: $("#id")
} else {
- elem = document.getElementById( match[3] );
+ elem = document.getElementById( match[2] );
if ( elem ) {
// Handle the case where IE and Opera return items
// by name instead of ID
- if ( elem.id !== match[3] ) return rootjQuery.find( selector );
+ if ( elem.id !== match[2] ) {
+ return rootjQuery.find( selector );
+ }
// Otherwise, we inject the element directly into the jQuery object
this.length++;
// check if an element is in a (or is an) XML document
isXMLDoc: function( elem ) {
- return (elem.ownerDocument || elem).documentElement.nodeName !== "HTML";
+ // documentElement is verified for cases where it doesn't yet exist
+ // (such as loading iframes in IE - #4833)
+ var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
+ return documentElement ? documentElement.nodeName !== "HTML" : false;
},
// Evalulates a script in a global context