jQuery doesn't work after content is loaded via AJAX

后端 未结 9 1003
野的像风
野的像风 2020-11-22 15:21

On this page I have a jQuery popup window and thumbnail resizable images. If I mouse over on the thumbnails, the images are resizing perfectly. Also, when I click on the big

9条回答
  •  名媛妹妹
    2020-11-22 15:49

    Just an alternative.

    $(window).on('load', _ => {
        // some jQuery code ..
    })
    

    This binds any delegated handler to the window. It will fire once the window is fully loaded including all graphics/includes/hooks/requests not just the DOM.

    $(document).ready(_ => ... preserves events to be fired after only the DOM is ready which does not apply on dynamically loaded content by AJAX. Either you can run a function or any event when a specific element is fully loaded by defining it as @Anthony Grist explained in his answer or bind your load event to the window as shown above.

    https://api.jquery.com/load-event/
    https://api.jquery.com/on/#on-events-selector-data-handler

提交回复
热议问题