Sean Delaney
Sean Delaney

Reputation: 327

twitter bootstrap model event "shown" called twice using jquery on event handler

I load the Twitter Bootstrap Model (http://twitter.github.com/bootstrap/javascript.html#modals) using:

$("#multiple_choice_question").modal();

I then call jQuery's .on() even handler to perform some more actions once the Model has fully loaded but the .on() function seems to be called twice?

For example If I do this, I get two random numbers:

$("#multiple_choice_question").on("shown",function() {
    console.log(Math.floor(Math.random() * 101)); 
});

How can I stop this?

Upvotes: 4

Views: 3596

Answers (1)

ens
ens

Reputation: 68

@simo's answer of registering the event with .one('shown') worked for me. From the jQuery docs, use .one() to "Attach a handler to an event for the elements. The handler is executed at most once per element per event type."

Upvotes: 4

Related Questions