javascript - Reply to comment YouTube style - Stack Overflow

I'm trying to create a similar ments system to YouTube. What would be the easiest way of making a

I'm trying to create a similar ments system to YouTube. What would be the easiest way of making a reply textarea appear under a ment when the button is clicked? I assume duplicating the textarea and making it display:none for each ment is not necessary.

With textarea

<div class="ment">
  <p>Bla bla</p>
  <a hred="" id="reply">Reply</a>
  <textarea class="reply"></textarea>   
</div>

Without textarea

<div class="ment">
  <p>Bla bla2</p>
  <a hred="" id="reply">Reply</a>
</div>

jQuery

$('#reply').click(function(){

}

I'm trying to create a similar ments system to YouTube. What would be the easiest way of making a reply textarea appear under a ment when the button is clicked? I assume duplicating the textarea and making it display:none for each ment is not necessary.

With textarea

<div class="ment">
  <p>Bla bla</p>
  <a hred="" id="reply">Reply</a>
  <textarea class="reply"></textarea>   
</div>

Without textarea

<div class="ment">
  <p>Bla bla2</p>
  <a hred="" id="reply">Reply</a>
</div>

jQuery

$('#reply').click(function(){

}
Share Improve this question edited Nov 26, 2012 at 15:08 user2428118 8,1244 gold badges46 silver badges73 bronze badges asked May 26, 2012 at 15:31 dominodomino 7,34513 gold badges39 silver badges50 bronze badges 2
  • meh. in the time it took me to type the answer, two other people had already posted near identical answers. – Spudley Commented May 26, 2012 at 15:44
  • @Spudley that just says that the question was to easy. – e382df99a7950919789725ceeec126 Commented May 26, 2012 at 15:48
Add a ment  | 

3 Answers 3

Reset to default 3

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 ment. 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

IDs are supposed to be unique, so you shouldn't have multiple #replys. Instead, you may add a class to each.

<div class="ment">
  <p>Bla bla</p>
  <a hred="" class="reply-button">Reply</a>
</div>
$('.reply-button').click(function(){
  $(this).after($('<textarea>').attr('class','reply-box'));
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744938175a4602154.html

相关推荐

  • javascript - Reply to comment YouTube style - Stack Overflow

    I'm trying to create a similar ments system to YouTube. What would be the easiest way of making a

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信