Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set modal title

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">&times;</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

like image 713
Low Rider Avatar asked Dec 17 '16 06:12

Low Rider


People also ask

What is modal in CSS?

A modal is a dialog box/popup window that is displayed on top of the current page: Open Modal.

How do I open modal on top of another 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.

How do I make modal pop up the center of the screen?

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.


1 Answers

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/

like image 51
Bhumi Shah Avatar answered Oct 10 '22 16:10

Bhumi Shah