I'm trying to refactor js script without using jquery. And the most difficult part, to me, is to understand why addEventListener
is not equivalent to $().on()
. I need to add some listeners to a modal which is loaded after the DOM is built. So I did:
document.addEventListener("DOMContentLoaded", function(){
document.getElementById('form-modal').addEventListener('show.bs.modal', function () {
// Here the js logic relevant to the modal
console.log('loaded by pure js')
})
$('#form-modal').on('show.bs.modal', function () {
console.log('with help of jquery');
})
});
Why the pure javascript doesn't work while the jquery does? What am I missin?