Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reply to comment YouTube style

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(){

}
like image 221
domino Avatar asked Feb 21 '23 08:02

domino


2 Answers

Something like

$('#reply').click(function(){
  $(this).parent().append($('<textarea>').attr('class','reply'));
});

should do the job.

like image 146
user2428118 Avatar answered Mar 05 '23 21:03

user2428118


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

like image 29
e382df99a7950919789725ceeec126 Avatar answered Mar 05 '23 21:03

e382df99a7950919789725ceeec126