php - Show HTML for specific div on click -


i have html , ajax set if click image (the reply-quote class below), initiates ajax echo html elsewhere on page.

as shown below, html file contains same block of divs multiple times. problem that, if user clicks image, how can make ajax show html (within show-reply div) specific block , not of them?

<!-- block 1 --> <div class="style1">   <div class="style2">     <img src="image.png" class="reply-quote" />       <div class="style3">         <div class="style4">           <div id="show-reply"></div>           <div class="reply-box">             <form class="reply-container no-margin" method="post" action="">               <textarea class="reply-field" name="new_comment" placeholder="write reply..."></textarea>               <button name="submit" class="btn" type="submit">post</button>             </form>           </div>         </div>       </div>    </div>  </div>  <!-- block 2 --> <div class="style1">   <div class="style2">     <img src="image.png" class="reply-quote" />       <div class="style3">         <div class="style4">           <div id="show-reply"></div>           <div class="reply-box">             <form class="reply-container no-margin" method="post" action="">               <textarea class="reply-field" name="new_comment" placeholder="write reply..."></textarea>               <button name="submit" class="btn" type="submit">post</button>             </form>           </div>         </div>       </div>    </div>  </div> 

here's jquery have right now:

$(document).ready(function() {       $(".reply-quote").click(function() {     $.ajax({       url: 'assets/misc/show_reply.php', // file echoes html `show-reply` div       type: "post",       data: {post_id: $(this).attr('id')},       success: function(data) {         $("#show-reply").append(data); // problem lies       }     });   }); }); 

to understanding, have somehow implement $(this), parent(), find(), etc. instead of current line i'm using ($("#show-reply").append(data);). question is, should line if click image, shows html specific block?

please help!

first: id should unique in document, use class attribute instead show-reply , other elements id repeated

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

then need find show-reply next clicked reply-quote image

$(document).ready(function() {         $(".reply-quote").click(function() {         var $reply = $(this);         $.ajax({             url: 'assets/misc/show_reply.php', // file echoes html `show-reply` div             type: "post",             data: {post_id: $(this).attr('id')},             success: function(data) {                 $reply.closest('.comment-container').find(".show-reply").append(data);             }         });     }); }); 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -