I building a threaded comment system (Reddit-like) in Django 3.0
A comment can have as many replies as possible. For each comment made, a Reply form is shown below it. Now, if I don't hide the forms, the page looks very bad, cluttered with textareas.
I need the following: A 'Reply' button, clicking which the reply form can be displayed/hidden.
Here's what I have tried:
.replyForm
to the forms..hideBtn
to the hide Buttons. $(".hideBtn").click(function(){
$(".replyForm").toggle();
});
Now, this works fine, but clicking a reply button opens up all the forms at the same time.
This is expected as the class belonging to each form is the same.
id = "replyForm{{comment.id}}"
which renders as replyForm123
if comment.id = 123
I feel that I am complicating things way too much, I am very new to JS and JQuery, and I'am only using them because I couldn't find a pythonic/django-based way for doing this.
Is there a simpler, more elegant way for doing this? Any help is appreciated
Edit 1:
I have found a very simple solution using Bootstrap 4's collapse class , but still want to know the JQuery way of doing this.
Try this:
$(".replyForm").click(function(){
$(this).toggle();
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.