Reputation: 4883
I have a div set up that has dynamically loaded links.
<div class="module">
<a href="#" class="sidelink">
<a href="#" class="sidelink">
</div>
How can I set this up so that if their is 1 link or less in this div, to hide all (in this case the 1) link. Looking for a simple jquery solution/
Upvotes: 2
Views: 184
Reputation: 123749
Assuming you have many such sections you can do:
$('.module:not(:has("a:nth-of-type(2)"))').hide();
.module - selects all the module elements
Inorder to hide the modules, try:
$('.module:not(:has(a:gt(0)))').find('a').hide();
or just
$('.module a').filter(function(){
return $(this).siblings('a').length == 0;
}).hide();
Upvotes: 4
Reputation: 318372
toggle()
will hide/show based on a boolean, checking if there are more than one anchor would evaluate as true or false :
$('.module a').toggle($('.module a').length > 1);
and close the anchors.
Upvotes: 3