Home > front end >  how to remove eventhandler from bootstrap carousel indicator items
how to remove eventhandler from bootstrap carousel indicator items

Time:02-06

I am using bootstrap5 carousel, and I want to fire a custom event when the previous or next indicators are clicked. I want to prevent the default bootstrap event from firing. I have tried a bunch of different techniques, but with no success.

Does anyone know how to do this?

Mtia

CodePudding user response:

Check the official documentation. It has some listeners you can add to your JavaScript.

You need to make sure you add the Bootstrap CDN or the npm module with the JavaScript for it to work, though.

Bootstrap Documentation

Example

const myCarousel = document.querySelector("#myCarousel");
const carousel = new bootstrap.Carousel(myCarousel, { interval: 2500 });

myCarousel.addEventListener("slide.bs.carousel", () => { /* Do something... */ });

CodePudding user response:

Have you tried e.stopPropagation() or e.stopImmediatePropagation()

  •  Tags:  
  • Related