jQuery :button Selector

Beginner
5 min read
Updated: Nov 2026
3 examples
Selectors

Definition

: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']").

Syntax

Start with these common calls. Keep them short and readable.

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

$("button, input[type='button']")   // CSS-equivalent
$("form *").filter(":button")       // official speed tip
CallWhat it does
Selector string:button filter (best scoped to a form)
Form / contextAvoids buttons in unrelated widgets
.filter(":button")Official pattern after a pure CSS query
Return valuejQuery collection of button controls (may be empty)

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
":button"Used in .filter(":button"). Official pattern after a pure CSS query

Return Value

Return ValueDescription
See examplesCheck the examples below for what this API returns in common cases.

jQuery Examples

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.

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">.

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.

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 Selector — Select Checkboxes

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

:checkbox Selector — Select Checkboxes tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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