user007
user007

Reputation: 3243

Fire slid event on init of bootstrap carousel

I wan to fire slid event of bootstrap carousel at carousel initialization.

I wan to run a function on slid event

$('#carousel').on('slid', function () {
// do something…
})

The above code is working well, but when carousel init then its first carousel item dont fire slid.

Please tell me how fire slid on carousel init

Upvotes: 2

Views: 1864

Answers (1)

colestrode
colestrode

Reputation: 10658

You can use the trigger() function to fire the slid event after you initialize your carousel:

$('#carousel').carousel();
$('#carousel').on('slid', function () {
    // do something…
})
$('#carousel').trigger('slid');

Working Demo

Upvotes: 2

Related Questions