Skip to content

Commit e300eeb

Browse files
committed
Fix issue with matching :reset selector, add unit tests for :submit, :reset, and :button. Fixes #9154.
1 parent 4bcc097 commit e300eeb

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

sizzle.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,8 @@ var Expr = Sizzle.selectors = {
654654
},
655655

656656
reset: function( elem ) {
657-
return elem.nodeName.toLowerCase() === "input" && "reset" === elem.type;
657+
var name = elem.nodeName.toLowerCase();
658+
return (name === "input" || name === "button") && "reset" === elem.type;
658659
},
659660

660661
button: function( elem ) {

test/unit/selector.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ test("pseudo - child", function() {
406406
});
407407

408408
test("pseudo - misc", function() {
409-
expect(10);
409+
expect(19);
410410

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

423+
var tmp = document.createElement("div");
424+
tmp.id = "tmp_input";
425+
document.body.appendChild( tmp );
426+
427+
jQuery.each( [ "button", "submit", "reset" ], function( i, type ) {
428+
var input = document.createElement( "input" );
429+
input.id = "input_" + type;
430+
input.setAttribute( "type", type );
431+
tmp.appendChild( input );
432+
433+
var button = document.createElement( "button" );
434+
button.id = "button_" + type;
435+
button.setAttribute( "type", type );
436+
tmp.appendChild( button );
437+
438+
t( "Input Buttons :" + type, "#tmp_input :" + type, [ "input_" + type, "button_" + type ] );
439+
440+
ok( (window.Sizzle || window.jQuery.find).matchesSelector( input, ":" + type ), "Input Matches :" + type );
441+
ok( (window.Sizzle || window.jQuery.find).matchesSelector( button, ":" + type ), "Button Matches :" + type );
442+
});
443+
444+
445+
document.body.removeChild( tmp );
446+
423447
var input = document.createElement("input");
424448
input.type = "text";
425449
input.id = "focus-input";

0 commit comments

Comments
 (0)