Sample html markup below
<div class="container answer_comments">
<p class="comment_text">Hey that's not cool.</p>
<p class="comment_attribs">By Anonymous User on 01 Dec</p>
<p class="comment_text">Is that really why?</p>
<p class="comment_attribs">By person on 27 Nov</p>
<p class="close_comments" onclick="close_comments()">Close</p>
</div>
JS function:
function close_comments() {
var comments_wrapper = $(this).closest('.answer_comments');
comments_wrapper.slideUp();
}
.answer_comments will not close. is that because im using $(this) wrong? This div is repeated many times on the page, what would be the best way to achieve what I’m trying to do?
check what “this” is, it’s probably referring to the function itself, not the element
change
to
and the function to
and see what happens