Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you close a jQuery Simplemodal?

Tags:

I want to close a Simplemodal window from a JavaScript function that gets called automatically after a form is submitted and the results recived (AJAX), using ASP.Net MVC. How do I close a jQuery Simplemodal?

I've opened it this way:

$("#popup").modal() 
like image 577
pupeno Avatar asked Jun 01 '09 16:06

pupeno


2 Answers

You have 2 options:

1) Put the close class (simplemodal-close) on an element in your modal data and SimpleModal will automatically bind the close function to the click event on that element.

Taking the example above, you'd want:

<div id="foo" style="display:none">   <p>Form HTML</p>   <span class="simplemodal-close">Close</span> </div> 

2) When you want to close the dialog programatically, call:

$.modal.close(); 

HTH!

-Eric (SimpleModal author)

like image 136
Eric Martin Avatar answered Nov 05 '22 20:11

Eric Martin


Just call close.

$("#popup").close(); 

If you're doing it for an ajax completion you need to add a callback. You may want to check for failure.

var foo = $("#popup").modal();  $.ajax({url:url, success:function(){     foo.close(); }}); 
like image 32
gradbot Avatar answered Nov 05 '22 21:11

gradbot