How to get element by its partial class name CSS

In the same way you can do this .class.class2.class3 { /*styles*/ } to target only things that have all 3 classes, you can can combine attribute selectors to do the same:

[class*="mybuttons-button"][class*="-large"] { /*styles*/ }

Granted it won’t work in a case like this:

<span class="my-buttons-button-color-small something-else-large"></span>

since it contains both mybuttons-button and -large.

If you didn’t think that would happen or be an issue you should be fine. Here’s a fiddle: http://jsfiddle.net/3wEJe/

Definitely wouldn’t recommend it though.

Leave a Comment

tech