jQuery - select subset of elements within a saved set of elements

后端 未结 5 1535
闹比i
闹比i 2020-12-11 04:26

From this:

var $saved = $(\'#parent\').find(\'a\');

How can I now subselect those elements in $saved which have class my

5条回答
  •  囚心锁ツ
    2020-12-11 05:14

    You can iterate through saved collection to find out the elements with class myClass.

    var $refined  = $saved.each(function(){
       if($(this).attr('class') == 'myClass')
          return $(this);
    });
    

    Or you can use filter() jquery function to apply selector.

     var $refined  = $saved.filter('myClass');
    

提交回复
热议问题