jquery:如果 child 有特定类(class)?

标签 jquery

我想知道如何确定 ul 是否有超过 2 个子级,以及此 ul 内是否有两个具有两个特定类别的子级……

if($(this).children().length > 2 && $(this).children('.section-title, .active')) {
    $(this).append('<li class="dots">&hellip;</li>');
}

???

最佳答案

var $ul = $('ul');
if($ul.find("li").length > 2 && $ul.find('.active, .inactive').length  == 2) {
       alert('yes, it is this way');
}​

<ul>
  <li class="active">Whatever</li>
  <li class="inactive">Whatever</li>
  <li>Whatever</li>
  <li>Whatever</li>
</ul>​

演示:http://jsfiddle.net/RtTSM/1/

关于jquery:如果 child 有特定类(class)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3176190/

相关文章:

javascript - LIightBox2 数据标题描述链接与 JavaScript

javascript - 带有 Ember CLI 的 jQuery UI

javascript - jQuery 无法识别 (+) 加号

javascript - 窗口调整大小函数运行两次

javascript - 如何清除窗口哈希而不重新加载?

javascript - 启用 Highcharts 、高库存滚动

javascript - 不使用 anchor 链接转到选项卡?

jquery - 单击一个时如何关闭其他 Accordion ,以及如何在隐藏父级时隐藏描述?

javascript - 滚动固定的 div 时防止正文滚动?

jquery - 使用 jQuery 删除元素