I have a show/hide effect that works but I just need to be able to use it multiple times in a page. Currently it toggles all elements. Can't get my head around how to do it.
Hope you can help.
I have a show/hide effect that works but I just need to be able to use it multiple times in a page. Currently it toggles all elements. Can't get my head around how to do it.
Hope you can help.
You can edit your function a bit to this, it'll work on each <ul>
indepdently:
$('.facet ul').each(function() {
if($(this).children('li:gt(9)').hide().length === 0) return;
$(this).append(
$('<li id="toggler">More</li>').toggle(function() {
$(this).text('Hide').siblings().show();
}, function() {
$(this).text('More').siblings('li:gt(9)').hide();
}));
});
Before, it was getting any li
over 9, you want to do this per <ul>
element with .each()
like the example above.
I removed a few bits to simplify, but you can see here for a working implementation... To keep the togglers as li elements, you'll need to expand this to selectively hide sibling elements - but I'm a fan of simplicity, so I'd suggest keeping the togglers outside of the element you want to show/hide.