OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Elementor Nested Carousel widget with remote buttons

  • Thread starter Thread starter Irakli Mosidze
  • Start date Start date
I

Irakli Mosidze

Guest
I want to make it go to a specific slide after clicking a specific button.

I am using the following code.

Code:
<script>
document.addEventListener('DOMContentLoaded', function() {
    const buttons = document.querySelectorAll('.slide-control');

    buttons.forEach(button => {
        button.addEventListener('click', function(event) {
            const slideIndex = parseInt(event.target.getAttribute('data-slide'), 10);

            // Log the slideIndex for debugging
            console.log('Button clicked. Slide index:', slideIndex);

            // Select the swiper container
            const carousel = document.querySelector('.elementor-widget-swiper-container .swiper-container');

            // Check if the carousel and swiper instance are found
            if (carousel) {
                console.log('Swiper container found:', carousel);

                if (carousel.swiper) {
                    console.log('Swiper instance found:', carousel.swiper);
                    carousel.swiper.slideTo(slideIndex - 1); // Swiper uses 0-based index
                } else {
                    console.error('Swiper instance not found on:', carousel);
                }
            } else {
                console.error('Swiper container not found. Ensure the selector is correct.');
            }
        });
    });
});
</script>

and the following for buttons

Code:
<button class="slide-control" data-slide="1">Slide 1</button>
<button class="slide-control" data-slide="2">Slide 2</button>
<button class="slide-control" data-slide="3">Slide 3</button>

But it doesn't work

<p>I want to make it go to a specific slide after clicking a specific button.</p>
<p>I am using the following code.</p>
<pre><code><script>
document.addEventListener('DOMContentLoaded', function() {
const buttons = document.querySelectorAll('.slide-control');

buttons.forEach(button => {
button.addEventListener('click', function(event) {
const slideIndex = parseInt(event.target.getAttribute('data-slide'), 10);

// Log the slideIndex for debugging
console.log('Button clicked. Slide index:', slideIndex);

// Select the swiper container
const carousel = document.querySelector('.elementor-widget-swiper-container .swiper-container');

// Check if the carousel and swiper instance are found
if (carousel) {
console.log('Swiper container found:', carousel);

if (carousel.swiper) {
console.log('Swiper instance found:', carousel.swiper);
carousel.swiper.slideTo(slideIndex - 1); // Swiper uses 0-based index
} else {
console.error('Swiper instance not found on:', carousel);
}
} else {
console.error('Swiper container not found. Ensure the selector is correct.');
}
});
});
});
</script>
</code></pre>
<p>and the following for buttons</p>
<pre><code><button class="slide-control" data-slide="1">Slide 1</button>
<button class="slide-control" data-slide="2">Slide 2</button>
<button class="slide-control" data-slide="3">Slide 3</button>
</code></pre>
<p>But it doesn't work</p>
 
Top