javascript - jquery load more content onclick - Stack Overflow

This is what I have so far:$(document).ready(function(){ $("#feed-page").load("feed.ph

This is what I have so far:

$(document).ready(function(){   
  $("#feed-page").load("feed.php #first-feed");

  $('.feed-load').click(function(){   
    $("#feed-page").load("feed.php #second-feed" ,  hideLoading);
    $(".feed-load .button-content").css( "display" , "none" );
    $('.feed-load-img').css( "display" , "block" );
  });

  function hideLoading() {  
    $(".feed-load .button-content").css( "display" , "block" );
    $(".feed-load .feed-load-img").css( "display" , "none" ); 
  }
}); // end document ready

My problem is that when I click on "load more" what happens is that the content gets swapped out.

That is not what I want to happen, I just want the content to all stay meaning the content that is already there on page load I want that to stay however when I click on "load more" I would like that content to stay but for some reason the content that was originally there gets swapped out with the new content which I don't want to happen.

A live example can be found here:

This is what I have so far:

$(document).ready(function(){   
  $("#feed-page").load("feed.php #first-feed");

  $('.feed-load').click(function(){   
    $("#feed-page").load("feed.php #second-feed" ,  hideLoading);
    $(".feed-load .button-content").css( "display" , "none" );
    $('.feed-load-img').css( "display" , "block" );
  });

  function hideLoading() {  
    $(".feed-load .button-content").css( "display" , "block" );
    $(".feed-load .feed-load-img").css( "display" , "none" ); 
  }
}); // end document ready

My problem is that when I click on "load more" what happens is that the content gets swapped out.

That is not what I want to happen, I just want the content to all stay meaning the content that is already there on page load I want that to stay however when I click on "load more" I would like that content to stay but for some reason the content that was originally there gets swapped out with the new content which I don't want to happen.

A live example can be found here: http://www.cyberfanatic.

Share Improve this question edited Jun 13, 2012 at 22:27 Zuul 16.3k6 gold badges62 silver badges88 bronze badges asked Jun 13, 2012 at 20:34 user1405690user1405690 1492 gold badges2 silver badges9 bronze badges 4
  • 6 My man... have you done any work yourself? – Norse Commented Jun 13, 2012 at 20:36
  • 3 Please post your code on jsfiddle then e back here and post the link to your jsfiddle. – pixeline Commented Jun 13, 2012 at 20:37
  • I would answer this but mattgemmell./2008/12/08/what-have-you-tried – Andrew Commented Jun 13, 2012 at 20:40
  • okay i have added what i have tried so far to the question so please review the question sorry for the way i posted it. – user1405690 Commented Jun 13, 2012 at 22:10
Add a ment  | 

1 Answer 1

Reset to default 3

The issue with your current code is that after the user clicks the button, you are loading the new data over the existent one. See jQuery .load().

What you need is to append the new data, in order to preserve the existent one:

// on click
$('.feed-load').click(function(){   

  // load the new data to an element
  $("<div>").load("feed.php #second-feed", function() {

    // all done, append the data to the '#feed-page'
    $("#feed-page").append($(this).find("#second-feed").html());

    // call your function
    hideLoading();
  });

  // continue the remaining of your code...
  $(".feed-load .button-content").css( "display" , "none" );
  $('.feed-load-img').css( "display" , "block" );
});

EDITED

Append with some animation as requested at the ment:

...
// all done, append the data to the '#feed-page'
var $html   = $(this).find("#second-feed").html(),
    $newEle = $('<div id="second-feed" />').attr("style", 'display:none;').html($html);

$("#feed-page").append($newEle);
$('#second-feed').slideToggle();
...

See this Fiddle Example!

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

相关推荐

  • javascript - jquery load more content onclick - Stack Overflow

    This is what I have so far:$(document).ready(function(){ $("#feed-page").load("feed.ph

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信