jQuery Find and List all LI elements within a UL within a specific DIV

后端 未结 4 1484
终归单人心
终归单人心 2020-12-09 02:49

I have 3 Columns of ULs each a Dynamic UL container that can have anywhere from 0-9 LI containers (eventually more). All my LI elements have an attribute \"rel\" which I am

4条回答
  •  孤街浪徒
    2020-12-09 03:15

    $('li[rel=7]').siblings().andSelf();
    
    // or:
    
    $('li[rel=7]').parent().children();
    

    Now that you added that comment explaining that you want to "form an array of rels per column", you should do this:

    var rels = [];
    
    $('ul').each(function() {
        var localRels = [];
    
        $(this).find('li').each(function(){
            localRels.push( $(this).attr('rel') );
        });
    
        rels.push(localRels);
    });
    

提交回复
热议问题