user3702848 user3702848 - 1 year ago 70
Javascript Question

Jquery open popup on button click for bootstrap

When i click below button

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal

I open below popup(modal)

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" 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>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
<div class="modal-body">
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>

I refer below example,

My question:

How can i open #myModal on button click by using javascript/jquery ?

Any help will be appreciated.


Answer Source

Give an ID to uniquely identify the button, lets say myBtn

// when DOM is ready
$(document).ready(function () {

     // Attach Button click event listener 

         // show Modal