【问题标题】:Add another CSS Style to Child Elements which are also Parents将另一个 CSS 样式添加到也是父元素的子元素
【发布时间】:2008-10-31 18:00:35
【问题描述】:

所以我的列表看起来像这样:

<div="list">
  <ul>
    <li class="page item">Parent 1
      <ul>
        <li class="page item">Child of Parent 1 and Parent of Grandchild
          <ul>
            <li class="page item">Grandchild</li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</div>

这是通过 Wordpress 的 list_wp_pages 以及自定义 CSS 吸盘式下拉 CSS 代码实现的。无序列表本身无法更改任何内容,因此我需要找到一种方法将 CSS 样式添加到仅作为父级的子页面(父级的子级 1...)。

我一直在尝试仅向具有自己的子页面的子页面添加箭头图标。我想我可以使用:

$("#target").addClass("newclass"); 

添加一个带有箭头图标的额外类作为背景图像。

谢谢!

【问题讨论】:

    标签: jquery parent children


    【解决方案1】:
    $("#target li").each(function() {
        if ( $("ul:eq(0)", this).length > 0 ) {
            $(this).addClass("class_name");
        }
    });
    

    检查#target 下的每个列表项以查看它是否至少有一个子无序列表,如果有,则将类名添加到它刚刚检查的列表项中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-25
      • 1970-01-01
      相关资源
      最近更新 更多