I would need to hide a div when user clicks a link.
The html is something like this:
<div class="item">
<div class="entry">
Lorem ipsum
</div>
<a href="#" class="commentsToggle">Show/hide comments</a>
<div class="comments hidden">
This comments div I want show/hide
</div>
</div>
<div class="item">
<div class="entry">
Lorem ipsum
</div>
<a href="#" class="commentsToggle">Show/hide comments</a>
<div class="comments hidden">
This comments div I want show/hide
</div>
</div>
....there's multiple items after this
As a default the comments are hidden (hence the class hidden there). Now if user clicks the Show/hide comments link it should show or hide comments for that specific item, depending are they visible or not. Now the question is do I need some id's to control js to hook only to that one specicif items ocmments and can I do it witouh id?
The js is something like atm:
$('.item .commentsToggle').click(function(){
elem = $(this).parents('.item');
$(elem).find('.comments').each(function() {
$(this).toggleClass('hidden');
});
});
If there's only one item that works but if multiple it breaks up :/
This is pretty simple.. I just dont get it into my head how to do it actually :D