I'm creating a series of comments, with replies to the comments below them. I use this code to append the new reply underneath the comment.
$(document).on('click', '.sub-reply1-send', function() {
var reply = $('textarea[name=comment-reply]').val();
$('.sub-reply1, .sub-reply1-textarea, .sub-reply1-send').slideUp(250).remove();
$('.answer').append("<div class='comment-sub-reply' style='display:none'>" + reply + "</div>");
$('.comment-sub-reply').slideDown(250);
subreply_visible = false;
});
This works fine if there's only one comment to reply to, but if there's two comments, let's say Comment1 and Comment2, Comment1 will be generated underneath Comment2. Replying to Comment1 will work fine, but replying to Comment2 would generate the reply-box underneath the last one in Comment1.
Is there any way for me to make it so that it appends to the comment that it's clicked from?
EDIT: HTML markup generated from what I have.
<div id="right-bar" class="flexcroll" style="display: block;">
<div class="question" style="display: block;">
<div class="question-content">What is the significance of this section?</div>
</div>
<div class="answer" style="display: block;">
<div class="question-answer" style="" id="thread1">This is not a test
<img class="reply" src="reply.png" />
</div>
<div class="question-answer" style="" id="thread0">Test
<img class="reply" src="reply.png" />
</div>
<div class="comment-sub-reply" style="">Another Test</div>
<div class="comment-sub-reply" style="">Still underneath Test</div>
<div class="comment-sub-reply" style="">This isn't a test either, but it's appearing under test</div>
<div class="sub-reply1" style="">
<textarea class="sub-reply1-textarea" name="comment-reply" style=""></textarea>
<div class="sub-reply1-send" style=""></div>
</div>
</div>
<div id="comment">
<form name="commentForm">
<textarea type="text" name="comment" id="answer-text-input" align="top" class="flexcroll" style="display: block;"></textarea>
</form>
<div id="button" style="display: block;"></div>
</div>
</div>
The other aspects of the JQuery don't affect it, only this one function creates sub-comments. So far, the unique thread IDs don't do anything, but I'm trying to make that work to seperate the comments.