jquery core: closes #5186. getElementsByTagName optimization was breaking the selecto...
[jquery.git] / src / core.js
index 6553258..45eaecf 100644 (file)
@@ -40,7 +40,8 @@ var jQuery = function( selector, context ) {
        // Save a reference to some core methods
        toString = Object.prototype.toString,
        push = Array.prototype.push,
-       slice = Array.prototype.slice;
+       slice = Array.prototype.slice,
+       indexOf = Array.prototype.indexOf;
 
 jQuery.fn = jQuery.prototype = {
        init: function( selector, context ) {
@@ -108,6 +109,11 @@ jQuery.fn = jQuery.prototype = {
                                        return this;
                                }
 
+                       // HANDLE: $("TAG")
+                       } else if ( !context && /^\w+$/.test( selector ) ) {
+                               this.selector = selector;
+                               selector = document.getElementsByTagName( selector );
+
                        // HANDLE: $(expr, $(...))
                        } else if ( !context || context.jquery ) {
                                return (context || rootjQuery).find( selector );
@@ -124,8 +130,7 @@ jQuery.fn = jQuery.prototype = {
                        return rootjQuery.ready( selector );
                }
 
-               // Make sure that old selector state is passed along
-               if ( selector.selector && selector.context ) {
+               if (selector.selector !== undefined) {
                        this.selector = selector.selector;
                        this.context = selector.context;
                }
@@ -522,6 +527,12 @@ jQuery.extend({
        }
 });
 
+if ( indexOf ) {
+       jQuery.inArray = function( elem, array ) {
+               return indexOf.call( array, elem );
+       };
+}
+
 // All jQuery objects should point back to these
 rootjQuery = jQuery(document);