Check if element contains any of the class from array

后端 未结 6 1039
一整个雨季
一整个雨季 2021-01-17 06:28

I have the following elements:

6条回答
  •  余生分开走
    2021-01-17 07:11

    Question depends on what you are trying to do.

    If you are trying to create a collection of those elements you can create a selector from the array:

    var elemCollection = $(  '.' + obj.join(',.') ).doSomething();
    

    Can also be used in filter()

    $existingElementCollection.filter(  '.' + obj.join(',.') ).doSomething();
    

    Or can be used in is()

    var filterSelector =  '.' + obj.join(',.');
    $someCollection.each(function(){
       if($(this).is( filterSelector ){
         // do somthing for matches
       }
    });
    

    DEMO

提交回复
热议问题