Monday, 9 September 2013

data attributes with bootstrap modal

data attributes with bootstrap modal

I'd like to pass arguments to modal window, such as title.
So I added data-titleto my link <a data-toggle="modal" href="#myModal"
class="btn" data-title="Title goes here">Launch demo modal</a> and of
course when the modal opens I'd like to replace the default title
...
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">&times;</button>
<h4 class="modal-title">Modal title</h4>
</div>
...
My JS goes like this but it doesn't set the proper title.
$('.modal-body', "#ModalWindow").html('<%= j render(template:
"tasks/new.html.erb") %>');
var Title = $(this).data('title');
$(".modal-title, #ModalWindow").text( Title );
$("#ModalWindow").modal('show');
Thanks for your help.

No comments:

Post a Comment