From 24db022ba06523f92e94ac5fa791fc4865b55ba7 Mon Sep 17 00:00:00 2001 From: John Resig Date: Sun, 19 Aug 2007 07:28:41 +0000 Subject: [PATCH] Added a fix for IE returning comment nodes in * queries. I put the logic in $.merge() but added a conditional such that the speed hit only effects IE users. (Bug #1155) --- src/jquery/jquery.js | 13 +++++++++++-- src/selector/selectorTest.js | 7 ++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 8420525..98cbf37 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -1725,8 +1725,17 @@ jQuery.extend({ merge: function(first, second) { // We have to loop this way because IE & Opera overwrite the length // expando of getElementsByTagName - for ( var i = 0; second[i]; i++ ) - first.push(second[i]); + + // Also, we need to make sure that the correct elements are being returned + // (IE returns comment nodes in a '*' query) + if ( jQuery.browser.msie ) { + for ( var i = 0; second[i]; i++ ) + if ( second[i].nodeType != 8 ) + first.push(second[i]); + } else + for ( var i = 0; second[i]; i++ ) + first.push(second[i]); + return first; }, diff --git a/src/selector/selectorTest.js b/src/selector/selectorTest.js index ac07bf3..7644fbe 100644 --- a/src/selector/selectorTest.js +++ b/src/selector/selectorTest.js @@ -1,8 +1,13 @@ module("selector"); test("element", function() { - expect(8); + expect(9); ok( $("*").size() >= 30, "Select all" ); + var all = $("*"), good = true; + for ( var i = 0; i < all.length; i++ ) + if ( all[i].nodeType == 8 ) + good = false; + ok( good, "Select all elements, no comment nodes" ); t( "Element Selector", "p", ["firstp","ap","sndp","en","sap","first"] ); t( "Element Selector", "body", ["body"] ); t( "Element Selector", "html", ["html"] ); -- 1.7.10.4