0

I have my modal defined in cshtml as shown below. When I click on the cross mark or on the close button, I want to perform some action but the hide event is not getting fired.

<div id="addD" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="addPatientLabel" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="addLabel">Create</h3> </div> <div class="modal-body"> <p class="validateTips"></p> <table> <tr> <td class="TemplateLabel"> Name: </td> <td align="left"> <input placeholder="name" type="text" name="Name" data-bind="value: NewP.Name" id="SignUpName" class="SignUp text ui-widget-content ui-corner-all" /> </td> </tr> </table> </div> <div class="modal-footer"> <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button> <button class="btn btn-primary" onclick="SaveD()">Save changes</button> </div> </div> 

Here is my js code:

$(document).ready(function () { $('#AddD').on("hidden", function () { debugger; alert("blah"); }); } 
3
  • check your ID in html vs. the ID in javascript. mismatch? Commented Jul 21, 2014 at 15:29
  • why don't you use live bootstrap sample ? Commented Jul 21, 2014 at 15:32
  • Yes, the ID was a mismatch. It works now. Thank you Commented Jul 21, 2014 at 16:11

2 Answers 2

1

It seems that you give the id of '#addD' to the modal and then expect the element $('#AddD') to trigger the event.

Sign up to request clarification or add additional context in comments.

3 Comments

This does not resolve the entire issue as the event name is still wrong.
The event name is not wrong as the user seems to be using bootstrap 2 at least according to modal window markup getbootstrap.com/2.3.2/javascript.html#modals
Although if user is using bootstrap3 then the event should be 'hidden.bs.modal' indeed :)
1

For Bootstrap 3.0:

According to the docs, the available event types are as follows:

  • show.bs.modal
  • shown.bs.modal
  • hide.bs.modal
  • hidden.bs.modal
  • loaded.bs.modal

You have to use the properly namespaced event like this:

$('#addD').on("hidden.bs.modal", function () { alert("blah"); }); 

Also, as was already pointed out, the ID selector was different between your HTML and Javascript

Demo in jsFiddle

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.