Destroy/remove bootstrap carousel

Viewed 2026

First, I created a virtual carousel (carousel elements) and then initialize it

$('#first-carousel').carousel();

Now, I run unto scenario where if window width is less than 480 then remove that carousel (#first-carousel').

How to remove bootstrap carousel? Tried to check its doc but seems there's no something like destroy or remove function or any related. Tried

$('#first-carousel').remove();
$('#first-carousel').unbind();

but seems not working, instead it gives me this error

bootstrap.min.js:6 Uncaught TypeError: Cannot read property 'offsetWidth' of undefined at c.slide (bootstrap.min.js:6) at c.next (bootstrap.min.js:6) at e (jquery.min.js:2)

any help, ideas?

2 Answers

Apparently there are no way to do it in Boostrap 3. What you can do is only initialize the carousel if the viewport is greater or equal to 480px.

if(window.innerWidth >= 480){
  $('#first-carousel').carousel();
}
Related