简体   繁体   中英

how to show div on under button on onclick event

From this code i have three button ,now i cliked ** Reply button 1** means i want to show one textarea for bottom of the button( Reply button 1).else i have to select Reply button 2 means i want show the textarea for under this Reply button 2..i don't know how to do.i am new developer please help me some one

 <div class="comment"> <div class="img-thumbnail"> <img class="avatar" alt="" src="../TV/dist/img/user2-160x160.jpg"> </div> <div class="comment-block"> <div class="comment-arrow"></div> <span class="comment-by"> <strong>Kani</strong> <span class="pull-right"> <a href="javascript:void(0)" rel="<?php echo $com['id']//1?>" class="reply-btn"><i class="fa fa-reply"></i> Reply button 1</a> </span> </span> <p>Lorem ipsum dolor sit amet,</p> <span class="date pull-right">19-Apr-2016 </span> </div> </div> <div class="comment"> <div class="img-thumbnail"> <img class="avatar" alt="" src="../TV/dist/img/user2-160x160.jpg"> </div> <div class="comment-block"> <div class="comment-arrow"></div> <span class="comment-by"> <strong>Kani</strong> <span class="pull-right"> <a href="javascript:void(0)" rel="<?php echo $com['id']//2?>" class="reply-btn"><i class="fa fa-reply"></i> Reply button 2</a> </span> </span> <p>Lorem ipsum dolor sit amet,</p> <span class="date pull-right">19-Apr-2016 </span> </div> </div> <div class="comment"> <div class="img-thumbnail"> <img class="avatar" alt="" src="../TV/dist/img/user2-160x160.jpg"> </div> <div class="comment-block"> <div class="comment-arrow"></div> <span class="comment-by"> <strong>Kani</strong> <span class="pull-right"> <a href="javascript:void(0)" rel="<?php echo $com['id']//3?>" class="reply-btn"><i class="fa fa-reply"></i> Reply button 3</a> </span> </span> <p>Lorem ipsum dolor sit amet,</p> <span class="date pull-right">19-Apr-2016 </span> </div> </div> 

After click that button i want to show this

  <textarea class="the-new-com"></textarea> 

Now this should help you surely. You need not use seperate ids for each

JS

$('.reply-btn').on('click',function() {
  $(this).closest('.comment').next('.reply').html("<div><textarea class='the-new-com'></textarea></div>");
})

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="comment">
  <div class="img-thumbnail">
    <img class="avatar" alt="" src="../TV/dist/img/user2-160x160.jpg">
  </div>
  <div class="comment-block">
    <div class="comment-arrow"></div>
    <span class="comment-by">
      <strong>Kani</strong>
      <span class="pull-right">
       <a href="javascript:void(0)" rel="<?php echo $com['id']//1?>" id="reply-btn-1" class="reply-btn"><i class="fa fa-reply"></i> Reply button 1</a>
      </span>
    </span>
    <p>Lorem ipsum dolor sit amet,</p>
    <span class="date pull-right">19-Apr-2016 </span>
  </div>

</div>
<div class="reply"></div>


<div class="comment">
  <div class="img-thumbnail">
    <img class="avatar" alt="" src="../TV/dist/img/user2-160x160.jpg">
  </div>
  <div class="comment-block">
    <div class="comment-arrow"></div>
    <span class="comment-by">
      <strong>Kani</strong>
      <span class="pull-right">
       <a href="javascript:void(0)" rel="<?php echo $com['id']//2?>"id="reply-btn-2" class="reply-btn"><i class="fa fa-reply"></i> Reply button 2</a>
      </span>
    </span>
    <p>Lorem ipsum dolor sit amet,</p>
    <span class="date pull-right">19-Apr-2016 </span>
  </div>

</div>
<div class="reply"></div>

<div class="comment">
  <div class="img-thumbnail">
    <img class="avatar" alt="" src="../TV/dist/img/user2-160x160.jpg">
  </div>
  <div class="comment-block">
    <div class="comment-arrow"></div>
    <span class="comment-by">
      <strong>Kani</strong>
      <span class="pull-right">
       <a href="javascript:void(0)" rel="<?php echo $com['id']//3?>" id="reply-btn-3" class="reply-btn"><i class="fa fa-reply"></i> Reply button 3</a>
      </span>
    </span>
    <p>Lorem ipsum dolor sit amet,</p>
    <span class="date pull-right">19-Apr-2016 </span>
  </div>

</div>
<div class="reply"></div>

use this below jQuery...and also include this below js library

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

$('.reply-btn').on('click',function() {
  $(this).after("<div><textarea class='addedText'></textarea></div>");
});

try this

$('div [id |=reply-btn]').on('click',function() {

  $(this).after("<div><textarea class='the-new-com'></textarea></div>");

});

https://jsbin.com/

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM