I have my modal:
<div id="defaultModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modal-title" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 class="modal-title" id="modal-title">Modal Title</h3>
</div>
<div class="modal-body" data-table="table" data-id="">
</div>
</div>
</div>
</div>
I have my button:
<button href="page.php" data-title="New Data" class='call-modal btn btn-success' >
<i class="glyphicon glyphicon-plus"></i>
</button>
And after click the button I use the class "call-modal":
$('.call-modal').on('click', function(e){
e.preventDefault();
$('#defaultModal')
.find('.modal-header > h3').text("Teste").end()
.find('.modal-body').load($(this).attr('href')).end()
.modal('show');
});
I can load the content but I would like to set the Title using the data-title.
Any idea why it is not working?
Thank you
A modal is a dialog box/popup window that is displayed on top of the current page: Open Modal.
To open a modal from another modal can be done simply by using the events that Bootstrap provides such as show. bs. modal . You may also want some CSS to handle the backdrop overlays.
Example 1: First, we will design modal content for the sign-up then by using CSS we will align that modal centered(vertically). Using the vertical-align property, the vertical-align property sets the vertical alignment of an element.
You can do like this:
$('#defaultModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget); // Button that triggered the modal
var modal = $(this);
var title = button.data('title'); alert(title);
modal.find('.modal-title').text(title)
});
and your button:
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#defaultModal" data-title="New Data" ><i class="glyphicon glyphicon-plus"></i></button>
fiddle:
http://jsfiddle.net/bhumi/hw154nda/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With