Please tell me why the on click event is repeated. Ie, when the modal window opens and we get to the event:

$(document).on("click", ".confirm-success", function(event) 

It is called several times. And if you open and close the window and click on the button, the event will be triggered every time one more time.

  $("body").on("click", ".ConfirmPostRequestToServer", function() { // данные самого окна var box_modal_id = getNewId(); var c = $('<div class="box-modal" />'); c.prepend('<div class="box-modal_close arcticmodal-close">X</div>'); c.attr('id', box_modal_id); // MODAL-CONFIRM var button = ''; button += '<div class="box-modal-confirm-button">'; button += '<button class="large green awesome confirm-success">Подтвердить</button>'; button += ' &nbsp; &nbsp; <button class="large awesome arcticmodal-close">Отмена</button>'; button += '</div><div class="modal-loader"></div>'; c.html('Предупреждение'+button); var arcticmodalData = {content: c}; $.arcticmodal(arcticmodalData); $(document).on("click", ".confirm-success", function(event){ event.preventDefault(); console.log(1); return false; }); return false; }); 
  • one
    So why do something different in one event? - iKNG
  • For me, the readability of the code is more convenient, there is no more. Is there a difference? - Nepster
  • one
    you add an event handler each time you click on .ConfirmPostRequestToServer - zb '

1 answer 1

The event inside must be removed and removed from there. return false; - you already have event.preventDefault(); You can also increment the button in one line: button += '<div class="box-modal-confirm-button"><button class="large green awesome confirm-success">Подтвердить</button>&nbsp;&nbsp;<button class="large awesome arcticmodal-close">Отмена</button></div><div class="modal-loader"></div>';