I'm trying to create a similar comments system to YouTube. What would be the easiest way of making a reply textarea
appear under a comment when the button is clicked? I assume duplicating the textarea
and making it display:none
for each comment is not necessary.
With textarea
<div class="comment">
<p>Bla bla</p>
<a hred="" id="reply">Reply</a>
<textarea class="reply"></textarea>
</div>
Without textarea
<div class="comment">
<p>Bla bla2</p>
<a hred="" id="reply">Reply</a>
</div>
jQuery
$('#reply').click(function(){
}
Something like
$('#reply').click(function(){
$(this).parent().append($('<textarea>').attr('class','reply'));
});
should do the job.
Depending on @user1419007 answer.
It already tests if you already have an textarea under the comment. If this is the case it will be send.
$('.reply').click(function(){
if($(this).parent().find('textarea').length < 1) {
$(this).parent().append($('<textarea>').attr('class','reply'));
} else {
alert('Sending: ' + $(this).parent().find('textarea').val());
}
});
Here is an example on JSFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With