Ann
Ann

Reputation: 135

Select div that ends with a class

Like this one:

<div class="abc foo-something">

How can I select div that has a class ending in -something?

Upvotes: 10

Views: 14194

Answers (1)

Sotiris
Sotiris

Reputation: 40096

@Einacio commented correct that $("div[class$='-something']") will not work for <div class="foo-something abc">. To select and this case you can add a second selector, with the following result:

$("div[class$='-something'],div[class*='-something ']")

This will select and classes that ending with -something and a space follows.

Check this for more info.

Upvotes: 23

Related Questions