How does jQuery’s "on" work?

Asked

Viewed 49 times

1

I’m doing some tests, and, I have some custom events on the platform I use, however, the window.addeventlistener does not work according to the on() of jQuery.

the event I use, let’s assume that the name is shoppingCartUpdated, it is triggered through the window.

As I do this in jQuery, it works normally

$(window).on('shoppingCartUpdated', function(e){
    console.log(e);
})

However, with addeventlistener, no.

window.addEventListener('shoppingCartUpdated', function(e){
   console.log(e);
});

I know they work differently, because otherwise jQuery’s people wouldn’t create the on. But, I’ve tried some ways to look at the source code of jQuery and I don’t quite understand how it works. It is possible to reproduce the same effect?

When I say "work", I mean that with jQuery I printed the console.log, with addEventListner no.

  • What is the evt that you passed to the addEventListener?

  • @Woss sorry, I edited. Now it’s right.

  • Another question: this your custom event, shoppingCartUpdated, is a Bubble Event? I mean, does it spread to the parent elements of the original target of the event? It would be interesting if you [Dit] the question and add information on how you created and fired the event.

  • @Woss as is the platform "Saas" that made this event, and not me, I can’t tell you that. I can know this information by some output on jQuery’s console? Can I paste what jQuery returns here...

  • Any extra information might be helpful... put what you can of event information in the question

  • How are you running the Rigger’s shoppingCartUpdated with pure Javascript?

  • If it’s of interest, I commented on the operation of jQuery.on in Events do not work with dynamic video?

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.