Targeting One Element Among Many Identical Buttons Using Attribute Selectors (Pluro Custom JS/CSS)
Why this problem exists
Modern websites often reuse the same CSS classes across multiple buttons and links for consistent styling (e.g., .hero__button.hero__button--primary). That’s great for design systems—but it becomes a challenge when you need to apply an accessibility fix (like updating an aria-label) to only one specific element.
If you update all elements by class, you risk:
-
Breaking accessibility labels site-wide
-
Changing behavior or styling unexpectedly
-
Creating regressions that are hard to debug
The solution is to use a selector that stays narrow and stable, combining the shared class with a unique attribute such as href, aria-label, or a container scope.
The safest approach: class + unique href
If a specific button points to a unique URL, you can target it precisely with an attribute selector:
Why this is safe
-
The class ensures you’re still matching the correct component type.
-
The
hrefmakes the selector unique, so other buttons with the same classes won’t be affected.
Important detail: In your message you wrote
hero_button, but your HTML showshero__button.
CSS selectors must match exactly (including underscores).
Alternative targeting strategies
Sometimes href isn’t stable or isn’t unique. Here are other options:
1) Target by aria-label (only if it’s unique)
2) Target by container scope (preferred when you have a unique section)
If the button is inside a unique hero section:
3) Target by visible text (least stable)
Text changes with marketing edits, translations, or A/B tests:
Accessibility note: what should an aria-label contain?
aria-label should provide a clear purpose (especially for screen reader users).
A label like "Shlomi" may not communicate what the link does.
A more accessible pattern is:
-
“Shlomi — Luxury Hotel Mattresses Collection”
-
or in Hebrew: “shlomi-example”
Example:
Using this approach in Pluro
When applying fixes via Pluro Custom JS/CSS:
-
Keep selectors tight (class + unique attribute).
-
Wrap JS in an IIFE (
(function(){...})();) to avoid global pollution. -
Add null guards (
if (!btn) return;) so the fix doesn’t throw errors. -
Test:
-
Keyboard navigation
-
Screen reader announcement (NVDA/JAWS/VoiceOver)
-
Multiple pages where the class appears
-
This method lets you deploy precise accessibility improvements without touching the site’s codebase—a practical approach when you need safe, targeted fixes at scale.