Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get class containing string and number from multiple classes

I have the image below with multiple classes. On click, I need to get the string "wp-image-1228" (those four numbers will always be different) from all of the classes.

I've got the click down, but I can't seem to get what I need using .match.

<img class="size-post_gal wp-image-1228 aligncenter">
like image 372
frogg3862 Avatar asked Apr 22 '26 10:04

frogg3862


1 Answers

If you are in the jQuery .click() handler and need that ID that follows wp-image-:

var id = $(this).prop('class').match(/wp-image-([0-9]+)/)[1];
like image 63
Walter Tross Avatar answered Apr 24 '26 23:04

Walter Tross