Tuesday, 21 October 2014

Toggle div show not working after ajax request - Javascript / Ajax

I have a jquery toggle to show / hide a comments section on a div. However I have the comments section paginating, for some reason the ajax request is stopping the show/hide from working. Any ideas guys?
Jquery Code
    $('.show-all-comments').click(function() {
        $(this).parent().next('.comments-box').slideToggle("fast"); //slide following class called .comments-box
    });

    jQuery(function($) {  //function for pagination.
        $('.post-list').on('click', '#pagination a', function(e){
            e.preventDefault();
            var link = $(this).attr('href');
            console.log(link);
            $('.post-list').fadeOut(200, function(){
                $(this).load(link + ' .post-list', function() {
                    var link = $(this).attr('href');
                    $(this).fadeIn(100);
                });
            });
        })
HTML OUTPUT
<div class="large-5 medium-5 small-12 columns">
          <a class="show-all-comments btn-third-priority">See Comments</a>
        </div>
<div class="large-7 medium-7 small-12 columns">
          <p style="padding-top: 10px; margin-bottom: 4px; font-size:0.9em;">One Response to "Post"
</div>

<div class="comments-box">Content</div>
If I remove the pagination, show all posts on the page.

No comments:

Post a Comment