Skip to content
Permalink
Browse files

Make sure that [name=FOO] searches actually have the specified name (…

…IE includes elements that have the ID, as well).
  • Loading branch information
jeresig committed Feb 15, 2009
1 parent 2082770 commit 22c9c9b9d31933a3615892a3796f5d9d75bac104
Showing with 16 additions and 2 deletions.
  1. +8 −1 src/selector.js
  2. +8 −1 test/unit/selector.js
@@ -332,7 +332,14 @@ var Expr = Sizzle.selectors = {
},
NAME: function(match, context, isXML){
if ( typeof context.getElementsByName !== "undefined" ) {
var ret = context.getElementsByName(match[1]);
var ret = [], results = context.getElementsByName(match[1]);

for ( var i = 0, l = results.length; i < l; i++ ) {
if ( results[i].getAttribute("name") === match[1] ) {
ret.push( results[i] );
}
}

return ret.length === 0 ? null : ret;
}
},
@@ -144,7 +144,7 @@ test("class", function() {
});

test("name", function() {
expect(9);
expect(11);

t( "Name selector", "input[name=action]", ["text1"] );
t( "Name selector with single quotes", "input[name='action']", ["text1"] );
@@ -158,6 +158,13 @@ test("name", function() {

isSet( jQuery("#form").find("input[name=action]"), q("text1"), "Name selector within the context of another element" );
isSet( jQuery("#form").find("input[name='foo[bar]']"), q("hidden2"), "Name selector for grouped form element within the context of another element" );

var a = jQuery('<a id="tName1ID" name="tName1">tName1 A</a><a id="tName2ID" name="tName2">tName2 A</a><div id="tName1">tName1 Div</div>').appendTo('#main');

t( "Find elements that have similar IDs", "[name=tName1]", ["tName1ID"] );
t( "Find elements that have similar IDs", "[name=tName2]", ["tName2ID"] );

a.remove();
});


0 comments on commit 22c9c9b

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