如何添加一些自定义CSS的最后一个孩子只有可见与Jquery? [英] How to add some custom CSS for the last child only if visible with Jquery?

查看:117
本文介绍了如何添加一些自定义CSS的最后一个孩子只有可见与Jquery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我允许用户将列表的一部分隐藏/可见等。

I am allowing users to make parts of a list hidden/visible etc.

现在这里是我的列表:

基本列表,但最终列表项有一些自定义CSSborder-bottom:none - 只是为了更好一点。

Basic list, but the very end list item has some custom CSS "border-bottom: none" - just to make it a bit more nicer looking.

<ul>
      <li class="item">Item</li>
      <li class="widget">widget</li>
      <li class="item">Item</li>
      <li class="item">Item</li>
      <li class="widget">Widget</li>
      <li class="widget">Widget</li>
</ul>

当我使用最后 添加一些自定义CSS,它工作完美。我的问题是当我隐藏窗口小部件,它们被隐藏的意图,但自定义CSS被使用,因为这些是隐藏的,边框仍然显示。

When I use the last selector, to add some custom CSS, it works perfect. My problem is when I hide the widgets, they are hidden as intended, but the custom CSS is used on this and as these are hidden, the border still shows up.

推荐答案

使用可见 :visibleselector:

use the ":visible" selector:

$("li:visible:last").css("your css rules");

这篇关于如何添加一些自定义CSS的最后一个孩子只有可见与Jquery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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