jquery count li elements inside ul -> length?

后端 未结 10 1054
有刺的猬
有刺的猬 2020-12-29 17:42

If a ul has more than one li-element inside of it, something should happen, otherwise not!

What am I doing wrong?

if ( $(\'         


        
10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-29 18:41

    Another approach to count number of list elements:

    var num = $("#menu").find("li").length;
    if (num > 1) {
      console.log(num);
    }
    
    

提交回复
热议问题