I have used a bootstrap modal dialog that is opened by clicking button. When I click on button at the first time,modal is opened; by the second clicking, modal dialog does not show and this error is shown in firebug consol:
TypeError: $(...).modal is not a function
$(".bs-modal-dialog").modal();
how can i solve that? thanks...
these are my code:
<div class="modal fade bs-modal-dialog" id="modalDialog" tabindex="-1" role="dialog"
aria-labelledby ="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button class="close" aria-hidden="true" data-dismiss="modal" type="button">×</button>
<h4 id="mySmallModalLabel" class="modal-title"></h4>
</div>
<div class="modal-body">
</div>
</div>
</div>
<script>
function EditCompany(CoId) {
var link="@Url.Action("EditCompany", "Companies", new { area = "AdminsArea", CoId = "-1"})";
link=link.replace("-1",CoId);
$(".bs-modal-dialog").modal('show');
$(".modal-body").load(link);
$(".modal-content > .modal-header> #mySmallModalLabel").text("Edit Company");
}
<input type="button" name="EditCompany" value="Edit" onclick="EditCompany(@co.CompanyID)" class="btn btn-success"/>
If you want to prevent boostrap modal from closing by those actions, you need to change the value of backdrop and keyboard configuration. The default value of backdrop and keyboard is set to true . You can change the configuration in HTML or Javascript directly.
On Options chapter, in the page you linked, you can see the backdrop option. Passing this option with value 'static' will prevent closing the modal.
How check modal is open or not in jQuery? You can simply use the modal('show') method to show or open the modal window in Bootstrap using jQuery. Other related Bootstrap's modal methods are modal('hide') and modal('toggle') .
To trigger the modal window, you need to use a button or a link. Then include the two data-* attributes: data-toggle="modal" opens the modal window. data-target="#myModal" points to the id of the modal.
You don't need any JavaScript to do that, Bootstrap already comes with html attribute for that.
All you have to do this include data-toggle="modal" data-target="#myModal"
and it should trigger your modal.
bootply here
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