jQuery selector to target any CSS name (of multiple present) starting with a prefix?

Posted by John K on Stack Overflow See other posts from Stack Overflow or by John K
Published on 2010-12-24T05:26:34Z Indexed on 2010/12/24 5:54 UTC
Read the original article Hit count: 164

I'm considering one selection statement that would target one of many css class names in a single class attribute value based on a string prefix.

For example, I want any detail- prefixed class names to get targeted from the following sample links.

<a href="eg.html" class="detail-1 pinkify another">
<a href="eg.html" class="something detail-55 minded">
<a href="eg.html" class="swing narrow detail-Z">
<a href="eg.html" class="swing narrow detail-Z detail-88 detail-A">

It's reminiscent of how [class|="detail"] prefix selector works on a scalar attribute value, and also of .hasClass(className), but my question needs both concepts applied simultaneously.

Note: The detail- prefix won't necessarily be the first class name of the bunch.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery