0

I have a lot of jQuery functions. They work all fine. Now I need some modal windows which are loaded via Ajax. The content is loading fine too. But all jQuery functions won't work inside the modal. Now I put all my javascript stuff in a OnLoadFunction(). I call this on the main page when it loads and fire it up again after opening a modal. So the jQuery stuff work in the modal too. But with every click I do, jQuery fires the functions multiple times.

$(".something").click(function() {
    alert("Just an alert");
});

This alert comes once after clicking one time. At the second time it comes two times and so on. Also all Ajax posts: in a form with validation I can click 10 times on submit, after filling all fields correctly and clik submit for the 11. time, the form get submited 11 times!

How can I write jQuery stuff and use all of them in every modal and the main page?

  • 2
    The modal content loads after the event binding. You'll need to use [event delegation](http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements). – Jasen Jun 20 '15 at 00:39
  • 1
    Jason is right. I have already asked a similar question here:http://stackoverflow.com/questions/29305925/check-if-an-event-listener-is-already-listenning-to-an-object-to-avoid-duplicat, hope it helps – Adib Aroui Jun 20 '15 at 01:52

0 Answers0