How to add some custom CSS for the last child only if visible with Jquery?

元气小坏坏 提交于 2019-12-22 13:31:34

问题


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

Now here is my list:

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>

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.

My question is how do I apply CSS to only the last visible child?


回答1:


use the ":visible" selector:

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


来源:https://stackoverflow.com/questions/1241554/how-to-add-some-custom-css-for-the-last-child-only-if-visible-with-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!