Selecting by attributes (Should know)

In this section, we'll see how to select elements by their attributes paying attention to some quirks that can lead to an unexpected behavior.

Getting ready

These selectors are easily recognizable because they are wrapped by square brackets (for example, [selector]). This type of selector is always used coupled with other, like those seen so far, although this can be implicit as we'll see in few moments. In my experience, you'll often use them with the Element selector, but this can vary based on your needs.

How many and what are the selectors of this type? Glad you asked! Here is a table that gives you an overview:

Name

Syntax

Description

Contains

[attribute*="value"]

(for example input[name*="cod"])

Get Instant JQuery Selectors now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.