How do I target an HTML query selector element that contains a partial class? or What's the best way

22 Replies, 2026 Views

Hey! The `[class*="btn-"]` approach you mentioned is actually one of the cleanest ways to target an html query selector element that contains a partial class.

If you wanna get fancy, you could use `document.querySelectorAll('[class^="btn-"]')` to target classes that *start* with "btn-".

Regex might be overkill unless you're dealing with super complex patterns. Stick with CSS selectors—they’re fast and readable.

Check out MDN’s guide on attribute selectors for more tricks!

Messages In This Thread



Users browsing this thread: 1 Guest(s)