jQuery - match element that has a class that starts with a certain string

前端 未结 1 2029
一生所求
一生所求 2021-01-05 05:42

I have a few links that look like this:

 ... 

How can I bind a function to all e

相关标签:
1条回答
  • 2021-01-05 06:33

    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 讨论(0)
提交回复
热议问题