开发者

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
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜