How to get elements of specific class starting with a given string?

后端 未结 11 851
面向向阳花
面向向阳花 2021-02-03 21:19

I have a list of elements that have multiple classes, for example:


         


        
11条回答
  •  [愿得一人]
    2021-02-03 21:31

    You can use Regular Expression or split the class name.

    $(".etape").click(function(){
       var classes = $.grep(this.className.split(" "), function(v, i){
           return v.indexOf('btn') === 0;
       }).join();
    });
    

    http://jsfiddle.net/LQPh6/

提交回复
热议问题