jQuery .is() Method

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

What Is .is()?

.is() (since jQuery 1.0) checks whether at least one element in the current set matches a selector, callback, jQuery object, or DOM element. It returns true or false — perfect for if checks and event handlers.

Remember
$("#box").is(".active")          // true / false
$(event.target).is("li")         // click was on an <li>?
$("input").parent().is("form")   // official parent check

// Since 1.6:
$el.is(function () { … })        // callback test
$el.is($other)                   // overlap with a jQuery set?
$el.is(domNode)                  // same DOM element?

// Not a filter — returns boolean, not a new set
NeedUse
Yes/no test$el.is(selector)
Keep matching elements$el.filter(selector)
Drop matching elements$el.not(selector)
Has matching descendant$el.has(selector)
Find descendants$el.find(selector)

How to Use .is()

Build a jQuery set, then ask a yes/no question about it.

  1. Select elements ($("#box"), $(event.target), …).
  2. Pass a selector, callback (1.6+), jQuery object, or DOM element.
  3. Read the boolean — true if any element matches.
  4. Branch with if — do not expect a chainable jQuery object.
  5. In click handlers, test event.target to ignore child nodes.
PieceRequired?Role
jQuery setYesElements to test
selectorOne formSince 1.0 — CSS/jQuery selector
functionOne formSince 1.6 — return true to match
jQuery / ElementOne formSince 1.6 — compare against nodes
Return value—Boolean only

Pseudocode

Pseudocode
set = $(...)

function is(test):
    for each element in set:
        if element matches test:     // selector / callback / node
            return true
    return false

// Empty set → always false
// Never returns a new jQuery object

Cheat Sheet

Keep these facts handy while testing matches.

TopicDetail
Syntax$el.is(selector | fn | $set | element)
Since1.0 · function / selection / element since 1.6
Returnstrue or false
Modifies set?No
Any match?Yes — one hit is enough
Empty setAlways false
vs .filter()Boolean test vs keep matching elements
Event tip$(event.target).is("li")

Live Preview

Pick a demo element and see common .is() checks — same idea as the official jQuery API examples.

Hidden demo nodes below are tested with :first-child, .blue, and :contains('Peter').

Result
Ready — choose an element and click Run .is().

jQuery Examples

Short, copy-ready snippets. Open DevTools, or use Try It Yourself for a live editor.

Example 1 — Selector Test

Ask whether an element matches a class or tag.

jQuery
$("#out").text(
  "is .active? " + $("#box").is(".active") + "\n" +
  "is div? " + $("#box").is("div")
);
Try It Yourself

How It Works

  1. Select. $("#box") is the element to test.
  2. Class. .is(".active") asks if it has that class.
  3. Tag. .is("div") asks if it is a div.
  4. Result. Both return booleans for if checks.

Example 2 — Event Target (Official)

Only react when the click landed on an li itself — not a child.

jQuery
$("ul").on("click", function (event) {
  var target = $(event.target);
  if (target.is("li")) {
    $("#out").text("Clicked li: " + target.text());
  } else {
    $("#out").text("Clicked a child — ignored");
  }
});
Try It Yourself

How It Works

  1. Bubble. Clicks on children still reach the ul handler.
  2. Target. event.target is the real clicked node.
  3. Test. .is("li") is true only for the list item itself.
  4. Ignore children. A click on <strong> inside an li fails the test.

Example 3 — Official Parent Check

Is the checkbox’s immediate parent a form?

jQuery
var isFormParent = $("input[type='checkbox']").parent().is("form");
$("#out").text("isFormParent = " + isFormParent);
Try It Yourself

How It Works

  1. Find. Select the checkbox.
  2. Parent. Move one level up with .parent().
  3. Test. .is("form") checks that node’s tag.
  4. Note. A <p> wrapper would make this false.

Example 4 — Function Form (Since 1.6)

Return true from a callback when a custom test passes.

jQuery
var hasTwo = $("#item").is(function () {
  return $("strong", this).length === 2;
});
$("#out").text("Has two strong tags? " + hasTwo);
Try It Yourself

How It Works

  1. Callback. Runs for each element in the set.
  2. this. Current DOM node — search inside it.
  3. Test. Count nested strong tags.
  4. Return. Any true makes .is() return true.

Example 5 — Against a jQuery Set

Check whether each item belongs to another collection (official pattern).

jQuery
var $alt = $("#browsers li:nth-child(2n)");
var lines = [];
$("#browsers li").each(function () {
  lines.push($(this).text() + " → " + $(this).is($alt));
});
$("#out").text(lines.join("\n"));
Try It Yourself

How It Works

  1. alt. Even children (2nd, 4th) form a jQuery set.
  2. each. Visit every list item.
  3. is($alt). True when that item is in the alt set.
  4. Alt form. $alt.is(this) is the same idea with a DOM node.

Edge Cases & Pitfalls

Check these before relying on .is() in real handlers.

return

Not chainable like .filter()

.is() returns a boolean. Do not write $el.is(".x").css(…) — that will throw.

any

One match is enough

On a multi-element set, .is() is true if any element matches — not “all must match.”

empty

Empty set → false

$("#missing").is("div") is always false. Check .length if you need “exists” separately.

target

Test event.target, not only this

Clicks on children bubble. $(event.target).is("li") asks what was actually clicked.

Browser Support

.is() has been part of jQuery since 1.0. Selector form works everywhere jQuery runs. Function, jQuery-object, and DOM-element forms need jQuery 1.6+.

✓ Stable · jQuery 1.0+

jQuery .is()

Supported across jQuery 1.x–3.x. Prefer current jQuery 3.x so all .is() argument forms (selector, function, selection, element) are available.

100% Method support
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
.is() Universal

Bottom line: Safe everywhere jQuery runs. Remember: boolean return — use .filter() when you need a new set.

Performance Notes

ApproachCostBest for
$el.is("tag") / classCheapTypical if checks
$el.is(complexSelector)HigherKeep selectors simple when possible
$el.is(fn)DependsCustom logic — avoid heavy work per element
Huge sets tested oftenCan add upNarrow first; stop when you only need one hit

.is() can stop early once it finds a match. For hot paths, prefer simple selectors and small sets (for example $(event.target)).

Key Takeaways

  • Role: ask “does this match?” and get true/false.
  • vs filter: .is() tests; .filter() keeps matches.
  • Forms: selector (1.0) · function / jQuery / element (1.6+).
  • Events: $(event.target).is("li") ignores child clicks.

One line: .is() returns a boolean match test — use .filter() when you need the matching elements.

Frequently Asked Questions

.is() checks whether at least one element in the current jQuery set matches a selector, passes a callback, or matches a jQuery object or DOM element. It returns true or false — not a new jQuery object. Selector form since 1.0; function, selection, and element forms since 1.6.
.filter() returns a new jQuery object with matching elements. .is() returns a boolean — true if any element matches. Use .filter() to keep matches; use .is() inside if checks.
No. It only tests the current set and returns true/false. The original collection is unchanged — ideal in event handlers and conditionals.
When at least one element in the set satisfies the argument. An empty jQuery object always returns false.
Yes, since jQuery 1.6. .is(function(index, element) { … }) runs for each element. If any call returns true, .is() returns true. Inside the callback, this is the current DOM element.
When clicks bubble from children, $(event.target).is("li") checks whether the clicked node itself is a list item — not a span or strong inside it.

Next: .last() Method

Get the last element in the current matched set.

.last() 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.

10 people found this page helpful