views:

365

answers:

1

Hi Guys,

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?

+5  A: 

use the ":visible" selector:

$("li:visible:last").css("your css rules");
Scharrels
Thanks for the reply, doesn't work I'm afraid
Keith Donegan
Make sure you are using a jQuery version that supports the :visible selector.Could you paste the code you are using?
Scharrels
No probs, $("li:visible:last").css('border', '0px').css('padding-bottom', '0px').css('margin-bottom', '16px');
Keith Donegan
Oh and I am using Jquery 1.3.2
Keith Donegan
jQuery cannot set all css properties. 'border' might be too specific. Try using $("li:visible:last").css('border-bottom', '0px solid #000'). It might be easier to add a class to the last element using:$("li:visible:last").addClass("lastelement");you can then add the design rules in your css file.
Scharrels
Hey, no it works fine. I can view firebug to verify this. Thanks anyway
Keith Donegan