Hiding the next to last element

I have two(at least,they can be more) identical divs that contain two input element.
I want with the click of an icon to hide always the last of them…I use this:


There is a problem here,after the last div is hidden clicking the icon subsequently does not hide the last visible div…the above expression always target the last div visible or not.The purpose here is to hide always the last visible element.
Take a look at an example:fiddle
click the minus icon

You can use the :visible selector then:


Just note that this is a custom jQuery selector, not an actual CSS pseudo-class… in case you might want to use it in your styles. Because of this, it is also comparably expensive.

1 Like


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.