例では内包要素の数が2以下だと何もせずに、3より多いと文字色を変更しています。
sample
See the Pen 内包要素の数によって処理を変えるjQuery by takapen (@takapen) on CodePen.
html
- a
- a
- a
- a
- a
- a
jQuery
$(function(){
var arr = [];
$(".waku").each(function() {
var numListLength = $(this).find("li").length;//ulの中のリストを数える
arr.push( numListLength );//その数を配列に入れる
});
$.each(arr, function(index, value) {
if(value <= 2){//liの数が2つ以下は除外
return true;
}
$('.waku').eq(index).css('color','#a00');
});
});