jQuery check if element has a class beginning with some string

前端 未结 6 1982
面向向阳花
面向向阳花 2021-02-02 00:52

I need to loop through some elements in the page and then, for each one, if it had a class beginning with, for example, \"C\", do something.

$(\'#dialog li\').e         


        
6条回答
  •  天涯浪人
    2021-02-02 01:30

    For more elaborate filters than "starts with" you can use the filter() function:

    $('#dialog li').filter( function() { 
      // return true for every element that matches your condition
      return this.className.match(/^c/) != null;
    }).each(function(){
      //do something
    }
    

提交回复
热议问题