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

22 Replies, 1823 Views

Title: *"How do I target an html query selector element that contains a partial class?"*

Hey folks!

Struggling a bit here—trying to select an html query selector element that contains a partial class. Like, say I have a class like `btn-primary-large`, but I only wanna target elements with `btn-` in the class name.

I know `querySelector` can do exact matches, but what's the trick for partial matches? Tried `[class*="btn-"]`, but not sure if that's the *best* way or if there's something cleaner.

Any tips? Maybe a regex solution or am I overcomplicating it?

Thanks in advance! 🙌

(Also, if this has been asked before, sorry—my search-fu is weak today.)

Messages In This Thread
How do I target an HTML query selector element that contains a partial class? or What's the best way - by - 22-06-2024, 06:48 AM



Users browsing this thread: 1 Guest(s)