Question

  • Creator
    Topic
  • #4265258

    How can I reinitialize Slick carousel after appending new content via AJAX

    by hfarooq94 ·

    I’m building a light fixture e-commerce site using the Slick library to display product images in a gallery. The gallery initializes correctly on page load, but when I append new content via AJAX, the newly added images don’t work with the Slick functionality. Here’s the relevant code:

    HTML:

    <div id=”gallery-container”>
    <div class=”gallery”>
    Light Fixture 1
    Light Fixture 2
    </div>
    </div>

    JavaScript:

    $(document).ready(function() {
    $(‘.gallery’).slick(); // Initialize the gallery on page load
    });

    // AJAX to load more content
    $.ajax({
    url: ‘load-more.php’,
    success: function(data) {
    $(‘#gallery-container’).append(data);
    // The new content is added but the gallery isn’t reinitialized
    }
    });
    I tried calling .slick() after the content was appended, but it didn’t solve the problem. The new images appear as regular static images without the carousel functionality.

    How can I ensure the gallery reinitializes properly after new content is appended?

    • This topic was modified 1 week, 6 days ago by Avatar photoWizard57M-TR.
    • This topic was modified 1 week, 6 days ago by Avatar photokees_b.

You are posting a reply to: How can I reinitialize Slick carousel after appending new content via AJAX

The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our Community FAQs for details. All submitted content is subject to our Terms of Use.

All Answers

Viewing 0 reply threads