Reputation: 34884
I'm using a twitter bootstrap modal on a page. I need to pass some custom arguments to it. How can I do it? And how do I access them inside the modal?
<!-- show modal -->
$("#myModal").modal("show");
<!-- modal -->
#myModal.modal.fade{tabindex: -1, role: :dialog, "aria-labelledby" => "myModalLabel", "aria-hidden" => true}
.modal-dialog
.modal-content
.modal-header
%button{type: :button, class: "close", "data-dismiss" => :modal, "aria-hidden" => true}
×
%h4.modal-title#myModalLabel
Choose an address
.modal-body
My modal body
.modal-footer
%button{type: :button, class: "btn btn-primary"}
Ok
Upvotes: 0
Views: 1234
Reputation: 4883
You could try by using the data-*
attribute and jQuery.data() API.
Set your argument declaratively using data-*
attribute in your modal
tag:
<div class="modal fade" id="myModal" data-argument="the_argument" ...>
...
</div>
Or set it programatically using the jQuery.data() API:
$('#myModal').data('argument', the_argument);
Then, to access the argument inside the modal
, query it using the jQuery.data() API:
var the_argument = $('#myModal').data('argument');
jsfiddle example: http://jsfiddle.net/DRk6C/
Upvotes: 2