I have several classes that I want to select .group1-1 .group1-2 .group1-3, each one of these has 50 elements under it.
Is there a way to select all classes that start with group1 (so I end up selecting group1-1, group1-2, group1-3), something like $(".group1"+*)
You can also use something along the lines of this if you'd like to avoid regex:
$("[class^='group1-']").click(function () {
var groupNumber = $(this).attr('class').split('-')[1];
alert('Yep, you clicked group1-' + groupNumber);
});
Example here: http://jsfiddle.net/iwasrobbed/7bjtb/
This question discusses jquery wildcard / regex selectors. Which basically allow you to use a regular expression to specify matching classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With