Skip to content
Permalink
Browse files

Provide a graceful failover for [name=foo] queries that are looking f…

…or non-input/iframe/form elements. Fixes jQuery bug #4081.
  • Loading branch information
jeresig committed Feb 14, 2009
1 parent 782b4af commit 21dde30348fe9bcbd8db8c1b30e470a9e2f39c16
Showing with 8 additions and 5 deletions.
  1. +3 −2 src/selector.js
  2. +2 −2 test/index.html
  3. +3 −1 test/unit/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){
@@ -121,8 +121,8 @@ <h2 id="userAgent"></h2>
<input name="types[]" id="types_movie" type="checkbox" value="movie" />
</form>

<div id="fx-queue">
<div id="fadein" class='chain test'>fadeIn<div>fadeIn</div></div>
<div id="fx-queue" name="test">
<div id="fadein" class='chain test' name='div'>fadeIn<div>fadeIn</div></div>
<div id="fadeout" class='chain test out'>fadeOut<div>fadeOut</div></div>

<div id="show" class='chain test'>show<div>show</div></div>
@@ -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"] )

0 comments on commit 21dde30

Please sign in to comment.
You can’t perform that action at this time.