I'm using Remodal Javascript lib to handle with modal windows. The point is that the library has handlers for custom events, e.g. the following javascript
$(document).on('opening', '.remodal', function (e) {
console.log('opening');
});
will be triggered when a modal window is open by clicking on another DOM element.
<a data-remodal-target="modal-window-id" id="trigger">CLICK ME TO OPEN MODAL</a>
<div class="remodal data-remodal-id="modal-window-id>MODAL CONTENT</div>
Now, If I add in a javascript file also the following call to a click event
$(document).on('click', '#trigger', function (e) {
console.log('trigger clicked');
});
regardless of the position of the previous script (i.e. before or after the other), I see that the opening
event is fired before. I know, in Javascript there is not really a guarantee of event execution, apart from some exeptions or when using jQuery (e.g. attaching the listeners in the proper sequence).
Now, how can I manage to execute click
before opening
? It occurs before, but somehow there should be another click
listener attached to that anchor that is executed before.
Any idea?