将另外的CSS样式添加到也是父元素的子元素中 [英] Add another CSS Style to Child Elements which are also Parents

查看:396
本文介绍了将另外的CSS样式添加到也是父元素的子元素中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So my list looks something like this:

<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的子级...).

This is through Wordpress' list_wp_pages along with a custom CSS suckerfish-like dropdown CSS code. Nothing can be changed in the unordered list itself, so I need to find a way to add a CSS style to only child pages that are also parents (Child of a Parent 1...).

我一直试图仅向具有自己的子页面的子页面添加箭头图标.我认为我可以使用:

I've been trying to add an arrow icon only to child pages that have child pages of their own. I figured that I could use:

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

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

to add an extra class with an arrow icon as a background image.

谢谢!

推荐答案

$("#target li").each(function() {
    if ( $("ul:eq(0)", this).length > 0 ) {
        $(this).addClass("class_name");
    }
});

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

Checks every list item under #target to see if it has at least one child unordered list, and if it does, then it adds a class name to the list item it just checked.

这篇关于将另外的CSS样式添加到也是父元素的子元素中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆