Search code examples
jqueryclassattributescontains

Select div (or other element) that class contains "grap" (o other specified word) for example


First of all; example of HTML code:

<div class"grap1"> some conetent</div>
<div class"grap2"> some conetent</div>
<div class"grap3"> some conetent</div>
<div class"blabla">some content></div>

And now i want to select divs that class contains "grap" word somewhere is class name (so in this case first three divs). How can i achieve that ?

This is not working: http://api.jquery.com/attribute-contains-word-selector/


Solution

  • Use the attribute contains selector:

    $('div[class*="grap"]')