skip to Main Content

I need your help. I tried this code which works but works not how I want.

$("ul").each(function(){
  let thisClass = $(ul).find('.className')
  if(thisClass.length >= 2){
    thisClass.addClass('done');
  }
});

It counted together all elements what I do not want. I want to count separately but I do not know how can goes.

<ul><li></li></ul>
<ul><li></li></ul>

Please help me if you can.
Thanks.

2

Answers


  1. Maybe something like:

    $("ul").each(function(i,v){  
      let thisClass =$(v).find('.className')  
      if(thisClass.length >= 2){
        thisClass.addClass('done');
      }
    });
    
    Login or Signup to reply.
  2. It’s a bad idea to use jQuery with Angular, re-think!

    Check the code where that list is rendering, and you will have the list of items.
    Just get the length of those items.

    You are rendering two list means two different variables

    list1.length
    list2.length
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search