jQuery :button Selector

Beginner
6 min read
Updated: Oct 2026
5 examples
Live preview

What Is :button?

:button (since jQuery 1.0) selects every <button> element and every <input type="button">. It does not match submit or reset inputs. Official CSS equivalent: $("button, input[type='button']").

Remember
$(":button")
  ✓ <button>…</button>
  ✓ <input type="button">
  ✗ <input type="submit">
  ✗ <input type="reset">

$("button, input[type='button']")   // CSS-equivalent
$("form *").filter(":button")       // official speed tip
NeedUse
Both button kinds$(":button")
Only <button> tags$("button")
Native-friendly$("button, input[type='button']")
Submit controls$(":submit")
All form controls$(":input")

How to Use :button

Scope to a form, then count, style, or disable every button control.

  1. Prefer $("form :button") over bare $(":button") on large pages.
  2. Remember it includes input[type="button"] — not just <button>.
  3. For speed: $("button, input[type='button']") or $("form *").filter(":button").
  4. Use :submit / :reset when you need those input types instead.
PieceRequired?Role
Selector stringYes:button filter (best scoped to a form)
Form / contextRecommendedAvoids buttons in unrelated widgets
.filter(":button")OptionalOfficial pattern after a pure CSS query
Return value—jQuery collection of button controls (may be empty)

Pseudocode

Pseudocode
matches = []
for each element in search context:
    if element.tag is button:
        matches.add(element)
    else if element.tag is input
         and element.type is "button":
        matches.add(element)

return matches

// Faster pattern:
candidates = querySelectorAll("button, input[type='button']")
return jQuery(candidates)

Cheat Sheet

Keep these facts handy while selecting button controls.

TopicDetail
Syntax$(":button") / $("form :button")
SincejQuery 1.0 · jQuery extension
Matchesbutton + input[type=button]
Skipssubmit, reset, other input types
CSS equivalent$("button, input[type='button']")
Speed tip$("form *").filter(":button")
Official demoMark matches; report .length
Native CSSNo — use CSS + .filter()

Live Preview

Run different selectors against a small sample form and see which button controls match.

Sample markup mirrors the official jQuery form demo (input button, checkbox, submit, text, and a <button>).

Result
$(":button")
matched: 2
labels: Input Button, Button

/* button tag + input[type=button] */

jQuery Examples

Short, copy-ready snippets. Open a browser with jQuery loaded, or use Try It Yourself for a live editor.

Example 1 — Official Demo: Count :button

Mark all button controls and report how many matched (jQuery API example).

jQuery
var input = $(":button").addClass("marked");
$("div").text("For this type jQuery found " + input.length + ".");

// Prevent the form from submitting
$("form").on("submit", function (event) {
  event.preventDefault();
});
Try It Yourself

How It Works

  1. Select. $(":button") finds both button kinds on the page.
  2. Mark. .addClass("marked") styles every match.
  3. Count. .length is written into a message div.
  4. Guard. preventDefault stops accidental form submit in the demo.

Example 2 — :button vs $("button")

The tag selector misses input[type="button"].

jQuery
console.log(":button →", $(":button").length);
console.log("button tag →", $("button").length);

// :button → 2
// button tag → 1  (misses input[type=button])
Try It Yourself

How It Works

  1. Pseudo-class. :button includes both <button> and input[type=button].
  2. Tag only. $("button") matches element name alone.
  3. Gap. Older markup often uses <input type="button">.
  4. Choose. Use :button when both kinds exist.

Example 3 — CSS-Equivalent Selector

Official docs: the valid CSS form is button, input[type='button'].

jQuery
var $a = $(":button");
var $b = $("button, input[type='button']");

console.log($a.length === $b.length);
// true — same match set, CSS form is faster
Try It Yourself

How It Works

  1. Same intent. Both selectors target the same two element kinds.
  2. Native path. The CSS string can use querySelectorAll.
  3. Extension cost. Bare :button cannot use that boost.
  4. Habit. Prefer the CSS form in performance-sensitive code.

Example 4 — .filter(":button")

Official performance tip: CSS first, then filter with :button.

jQuery
var $fast = $("form *").filter(":button");

console.log($fast.length);
// 2 — same as $("form :button"), often faster
Try It Yourself

How It Works

  1. CSS pass. $("form *") uses the browser engine.
  2. Filter. .filter(":button") keeps only button controls.
  3. Scope. Starting inside form avoids unrelated widgets.
  4. Docs tip. This is the pattern jQuery recommends for extensions.

Example 5 — Not Submit or Reset

:button skips input[type=submit] and input[type=reset].

jQuery
console.log(":button →", $(":button").length);
console.log(":submit →", $(":submit").length);
console.log(":reset  →", $(":reset").length);

// :button skips submit/reset inputs
// use :submit / :reset for those types
Try It Yourself

How It Works

  1. Role split. Button, submit, and reset are separate selectors.
  2. :button. Only plain buttons and input[type=button].
  3. :submit / :reset. Target those input types (and matching buttons).
  4. Pick the right one. Do not assume “button-looking” means :button.

Edge Cases & Pitfalls

Check these before relying on :button in real forms.

trap

Submit looks like a button — it is not :button

input[type="submit"] needs :submit, not :button.

tag

<button type="submit"> still matches

Any <button> tag matches :button, even when its type is submit.

slow

Bare $(":button") scans the whole page

Scope with $("form :button") or use CSS + .filter(":button").

non-std

Not valid in querySelectorAll

Prefer $("button, input[type='button']") for native speed.

Browser Support

The :button pseudo-class is a jQuery extension and has worked since jQuery 1.0. Prefer the CSS equivalent button, input[type='button'], or a pure CSS query plus .filter(":button").

✓ jQuery 1.0+ · extension

jQuery :button Selector

Supported across jQuery 1.x, 2.x, and 3.x wherever your jQuery build runs. Prefer button, input[type='button']; use .filter(":button") after a CSS query for speed.

100% jQuery extension
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
:button Universal

Bottom line: Safe everywhere jQuery runs. Scope to a form; prefer the CSS-equivalent selector when performance matters.

Performance Notes

ApproachCostBest for
$("button, input[type='button']")FastestNative CSS equivalent (official)
$("form *").filter(":button")FastLarge forms / hot paths
$("form :button")CheapTypical tutorials and small pages
$(":button")SlowerAvoid — whole-document scan

Official jQuery docs note that because :button is not CSS, it cannot use the querySelectorAll boost. Select with a pure CSS selector first, then .filter(":button").

Key Takeaways

  • Role: match <button> and input[type=button].
  • Broader than tags: $(":button") ≠ $("button").
  • Not submit: use :submit / :reset for those inputs.
  • Speed: CSS equivalent or .filter(":button").

One line: $(":button") gathers <button> and input[type=button] — prefer the CSS equivalent when speed matters.

Frequently Asked Questions

:button selects every button element and every input whose type is exactly button. It does not select input type submit, reset, checkbox, or other control types.
$("button") matches only <button> tags. $(":button") also includes input[type="button"]. If your form uses both, :button gathers both kinds.
No. It is a jQuery extension since version 1.0. The CSS-equivalent selector is $("button, input[type='button']"). Native querySelectorAll cannot run :button directly.
No. input[type="submit"] is matched by :submit, not :button. A <button> element still matches :button even when type="submit", because it is a button tag.
Use $("button, input[type='button']") for native querySelectorAll speed, or select with a pure CSS selector then .filter(":button") as the official docs recommend.
In the official jQuery form demo, :button finds two elements — one input[type="button"] and one button element — while skipping submit, reset, text, and other controls.

Next: :checkbox

Select every checkbox input with the jQuery form pseudo-class.

:checkbox tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful