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

后端 未结 5 1536
闹比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:06

    You can use filter method:

    var $refined = $saved.filter(".myClass");
    
    0 讨论(0)
  • 2020-12-11 05:12
    $saved.each(function(){
                if($(this).hasClass('test')) alert($(this).text());
            });
    
    0 讨论(0)
  • 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');
    
    0 讨论(0)
  • 2020-12-11 05:28

    You can use filter method.

    var $refined = $saved.filter('.myClass');
    
    0 讨论(0)
  • 2020-12-11 05:32

    may be this one can help

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

    http://api.jquery.com/filter/

    0 讨论(0)
提交回复
热议问题