From: John Resig Date: Sat, 14 Feb 2009 22:24:55 +0000 (+0000) Subject: Provide a graceful failover for [name=foo] queries that are looking for non-input... X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;ds=sidebyside;h=21dde30348fe9bcbd8db8c1b30e470a9e2f39c16;hp=782b4af76ec080aad93d5c4a15fbc805f3e5960e;p=jquery.git Provide a graceful failover for [name=foo] queries that are looking for non-input/iframe/form elements. Fixes jQuery bug #4081. --- diff --git a/src/selector.js b/src/selector.js index dd05065..ecec83b 100644 --- a/src/selector.js +++ b/src/selector.js @@ -333,8 +333,9 @@ var Expr = Sizzle.selectors = { } }, NAME: function(match, context, isXML){ - if ( typeof context.getElementsByName !== "undefined" && !isXML ) { - return context.getElementsByName(match[1]); + if ( typeof context.getElementsByName !== "undefined" ) { + var ret = context.getElementsByName(match[1]); + return ret.length === 0 ? null : ret; } }, TAG: function(match, context){ diff --git a/test/index.html b/test/index.html index 2c3545f..c415d11 100644 --- a/test/index.html +++ b/test/index.html @@ -121,8 +121,8 @@ -
-
fadeIn
fadeIn
+
+
fadeIn
fadeIn
fadeOut
fadeOut
show
show
diff --git a/test/unit/selector.js b/test/unit/selector.js index 715823a..9be9383 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -134,12 +134,14 @@ test("class", function() { }); test("name", function() { - expect(7); + expect(9); t( "Name selector", "input[name=action]", ["text1"] ); t( "Name selector with single quotes", "input[name='action']", ["text1"] ); t( "Name selector with double quotes", 'input[name="action"]', ["text1"] ); + t( "Name selector non-input", "[name=test]", ["length", "fx-queue"] ); + t( "Name selector non-input", "[name=div]", ["fadein"] ); t( "Name selector non-input", "*[name=iframe]", ["iframe"] ); t( "Name selector for grouped input", "input[name='types[]']", ["types_all", "types_anime", "types_movie"] )