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

22 Replies, 1929 Views

For targeting an html query selector element with a partial class, `[class*="btn-"]` is the simplest solution.

If you’re working with a lot of dynamic classes, you *could* use regex, but it’s slower and harder to read.

CSS selectors are your best bet—fast and reliable.
`[class*="btn-"]` is the way! It’s the most efficient method for partial class matching in an html query selector element.

If you’re dealing with messy markup, test it thoroughly—sometimes classes get mangled by frameworks.

Regex is overcomplicating it unless you’ve got a *very* specific need.



Users browsing this thread: 1 Guest(s)