Calling function after .load (Jquery)

后端 未结 3 2003
一向
一向 2020-12-01 21:28

Having a little difficulty getting a function to call after a .load:

$(function(){
    $(\'a.pageFetcher\').click(function(){
        $(\'#main\').load($(thi         


        
3条回答
  •  误落风尘
    2020-12-01 21:49

    Your first point of reference should always be the jQuery API, here's what the API page on .load() tells you about the parameters the load function takes:

    .load( handler(eventObject) )

    .load( [eventData], handler(eventObject) )

    In this case, you're passing $(this).attr('rel') as the eventData, so you add your event handler after that:

    $('#main').load($(this).attr('rel'), onNewMainContent);
    

    In your second block of code, you're telling jQuery to execute it when your body loads, not when you load more into your site. You need to execute it specifically, so change the start of that function to:

    function onNewMainContent {  // new
      var $container = $('#container');
      $container.imagesLoaded(function(){
        $container.masonry({
          itemSelector: '.box',
      // ...
    

提交回复
热议问题