Skip to content

Commit

Permalink
Fix issue with matching :reset selector, add unit tests for :submit, …
Browse files Browse the repository at this point in the history
…:reset, and :button. Fixes #9154.
  • Loading branch information
jeresig committed May 9, 2011
1 parent 4bcc097 commit e300eeb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion sizzle.js
Expand Up @@ -654,7 +654,8 @@ var Expr = Sizzle.selectors = {
},

reset: function( elem ) {
return elem.nodeName.toLowerCase() === "input" && "reset" === elem.type;
var name = elem.nodeName.toLowerCase();
return (name === "input" || name === "button") && "reset" === elem.type;
},

button: function( elem ) {
Expand Down
26 changes: 25 additions & 1 deletion test/unit/selector.js
Expand Up @@ -406,7 +406,7 @@ test("pseudo - child", function() {
});

test("pseudo - misc", function() {
expect(10);
expect(19);

t( "Headers", ":header", ["qunit-header", "qunit-banner", "qunit-userAgent"] );
t( "Has Children - :has()", "p:has(a)", ["firstp","ap","en","sap"] );
Expand All @@ -420,6 +420,30 @@ test("pseudo - misc", function() {
t( "Text Contains", "a:contains(Google Groups (Link))", ["groups"] );
t( "Text Contains", "a:contains((Link))", ["groups"] );

var tmp = document.createElement("div");
tmp.id = "tmp_input";
document.body.appendChild( tmp );

jQuery.each( [ "button", "submit", "reset" ], function( i, type ) {
var input = document.createElement( "input" );
input.id = "input_" + type;
input.setAttribute( "type", type );
tmp.appendChild( input );

var button = document.createElement( "button" );
button.id = "button_" + type;
button.setAttribute( "type", type );
tmp.appendChild( button );

t( "Input Buttons :" + type, "#tmp_input :" + type, [ "input_" + type, "button_" + type ] );

ok( (window.Sizzle || window.jQuery.find).matchesSelector( input, ":" + type ), "Input Matches :" + type );
ok( (window.Sizzle || window.jQuery.find).matchesSelector( button, ":" + type ), "Button Matches :" + type );
});


document.body.removeChild( tmp );

var input = document.createElement("input");
input.type = "text";
input.id = "focus-input";
Expand Down

0 comments on commit e300eeb

Please sign in to comment.