javascript - How to slide down dynamic content using jQuery? -


i have comment system , implement "show replies (2)" slide down effect.

this example of setup.

<div class="comment">   <div class="main-comment">     message.   <a href="#" class="show-replies">show replies (1)</a>  </div>   <div class="sub-comment">   funny comment there, mate.  </div> </div> 

but because both main comment , sub comments dynamically generated using ajax, setting event handlers little tricky. how did it:

$(".comment").delegate('.show-replies', 'click', function(event) {   $(this).parent().next(".sub-comment").slidedown();  }); 

i've tried make setup simple , close real thing possible.

what doing wrong , how solve it?

 <div class="comment">   <div class="main-comment">     message.   <a href="#" class="show-replies">show replies (1)</a>  </div>   <div class="sub-comment" style="display: none">   funny comment there, mate.  </div> </div>   <script>   $(document).ready(function() {     $('.show-replies').on('click', function() {      $('.sub-comment').slidetoggle();     });   });  </script> 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -