jQuery - match element that has a class that starts with a certain string
I have a few links that look like this:
<a href="#" class="somelink rotate-90"> ... </a>
How can开发者_高级运维 I bind a function to all elements that have a class that starts with "rotate-
" ?
You can use starts with selector like this:
$('a[class^="rotate-"]')
Description: Selects elements that have the specified attribute with a value beginning exactly with a given string.
So your code should be:
$('a[class^="rotate-"]').click(function(){
// do stuff
});
Note: If you want to find out elements that contain certain text anywhere in their attributes, you should do this instead:
$('a[class*="rotate-"]').click(function(){
// do stuff
});
精彩评论