Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify multiple javascript modal parameters with Twitter Bootstrap?

I have a modal created using Twitter Bootstrap. I want to open using javascript. Right now I have the following:

<script type="text/javascript" id="js">$(document).ready(function() {
  $("#my-modal").modal('show')
});
</script>

However, I want to include the backdrop and keyboard attributes as well. Twitter's documentation show the options as:

$('#my-modal').modal({
  keyboard: true
})

$('#my-modal').modal({
  backdrop: true
})

Using any combination of the three options does not work. I'm not very good with javascript so I don't know what's going on. I'm reading javascript tutorials right now to see where I went wrong, but so far no luck.

Twitter Bootstrap's modal documentation

Thanks.

like image 668
Jonathan Ong Avatar asked Feb 22 '23 13:02

Jonathan Ong


1 Answers

I'm not familiar with Twitter Bootstrap, but from a quick glance at the reference you linked to it looks like .modal() method is taking an object to specify parameters so to specify multiple parameters you should be able to do this:

$('#my-modal').modal({
   show : true,
   keyboard : true,
   backdrop : true
});

The bit in the curly brackets {} is standard JavaScript object literal syntax, where you can specify multiple properties separated by commas.

like image 122
nnnnnn Avatar answered Mar 03 '23 13:03

nnnnnn