jQuery check if element has a class beginning with some string

前端 未结 6 1976
面向向阳花
面向向阳花 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:28

    Try the Attribute Starts With Selector. As a bonus, there is no need for the extra if.

    $('#dialog li[class^="C"]').each(function() {
        // do something
    });
    

提交回复
热议问题