I'm in the process of implementing a commenting system similar to Reddit on my website. Each comment is equipped with a small button in the top right corner that allows users to collapse the comment.
To achieve the collapsing effect, I am utilizing jQuery toggleClass.
$(".button").click(function() {
$('.bottomtext').toggleClass('bottomtext-small');
$('.upvote').toggleClass('upvote-small');
$('.downvote').toggleClass('downvote-small');
$('.main-content').toggleClass('main-content-small');
$('.button').toggleClass('button-small');
});
While the comment collapsing feature functions correctly on individual comments, toggling the class results in every comment collapsing. How can I ensure that only the comment associated with the clicked button is affected?
For a demonstration, view the JSFiddle: https://jsfiddle.net/j765rkpc/7/