[Fixed]-How do I get click event of model form button?

1👍

✅

Just attach your click event to already present element which seems to be div.infor-experience, since your modal html gets appended after DOM load. Also, make sure your script renders in web browser if you have provided any conditions for them to render.

$('.infor-experience').on('click', '.submit', function(e) {
        alert("TEST");
})

0👍

It might be that positioning of your script. At the time of its execution the DOM may not be ready or exist yet.

You could wrap your DOM related codes like so:

$(document).ready(init);

function init(){ 
  $('.add-to-list').on('click', '.submit', function(e) {
    alert("TEST");
  })
}

0👍

Try this instead

$(document).ready(function () {
    $('.add-to-list').on('click', '.submit', function(e) {
        alert("TEST");
    });
});

you should add the code under $(document).ready() so that it waits for whole DOM to load and then attaches the method instead doing so before loading of DOM.

Leave a comment