From 022ec82184890d357f14b9b00d64ca4b838a2469 Mon Sep 17 00:00:00 2001 From: Dan Shultz Date: Fri, 2 Nov 2012 14:19:58 -0400 Subject: [PATCH] binding close event with delegate from container If the html is late loaded into the modal or the html in the modal is changed, elements with the close class do not trigger close as the event is bound directly to the element vs the container element. --- src/jquery.simplemodal.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jquery.simplemodal.js b/src/jquery.simplemodal.js index aca49eb..505086c 100644 --- a/src/jquery.simplemodal.js +++ b/src/jquery.simplemodal.js @@ -376,7 +376,7 @@ var s = this; // bind the close event to any element with the closeClass class - $('.' + s.o.closeClass).bind('click.simplemodal', function (e) { + s.d.container.delegate('.' + s.o.closeClass, 'click.simplemodal', function (e) { e.preventDefault(); s.close(); }); @@ -422,7 +422,7 @@ * Unbind events */ unbindEvents: function () { - $('.' + this.o.closeClass).unbind('click.simplemodal'); + s.d.container.undelegate('.' + s.o.closeClass, 'click.simplemodal'); doc.unbind('keydown.simplemodal'); wndw.unbind('.simplemodal'); this.d.overlay.unbind('click.simplemodal');