From 858d56fc8e26a686cb19d1e35b0c2e8953987e49 Mon Sep 17 00:00:00 2001 From: Ariel Flesler Date: Thu, 8 May 2008 16:14:49 +0000 Subject: [PATCH] jquery core: closes #2771 $.inArray now makes a === check because of IE. $.inArray is used in $.fn.index, this is shorter, and breaks the loop when possible. $.fn.index can receive a jquery object, and the first element is used --- src/core.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/core.js b/src/core.js index 500e400d9..42fd8d499 100644 --- a/src/core.js +++ b/src/core.js @@ -140,12 +140,10 @@ jQuery.fn = jQuery.prototype = { var ret = -1; // Locate the position of the desired element - this.each(function(i){ - if ( this == elem ) - ret = i; - }); - - return ret; + return jQuery.inArray( + // If it receives a jQuery object, the first element is used + elem && elem.jquery ? elem[0] : elem + , this ); }, attr: function( name, value, type ) { @@ -1124,7 +1122,8 @@ jQuery.extend({ inArray: function( elem, array ) { for ( var i = 0, length = array.length; i < length; i++ ) - if ( array[ i ] == elem ) + // Use === because on IE, window == document + if ( array[ i ] === elem ) return i; return -1; -- 2.39.5