Mathematics
Mathematics

Reputation: 7618

Regex to filter images based on text

I have this,

<td class="optionsImg" style="display:none;">
    <img src="../status/approved-01.png" />
    <img src="../status/rejected-02.png" />
    <img src="../status/pending-01.png" />
</td>

and I am trying this,

var allImages = $(".optionsImg").find("img");

Now I need to select image that has "-02.png" in above using any possible technique, I want to keep it as short as possible

Upvotes: 1

Views: 176

Answers (1)

Tushar
Tushar

Reputation: 87203

Use attribute-value ends with selector to select all the images whose src attribute value ends with -02.png.

 $('.optionsImg img[src$="-02.png"]')

If you want to select images containing string anywhere in the value use attribute-value contains selector.

 $('.optionsImg img[src*="-02.png"]')

Upvotes: 6

Related Questions