Are JQuery events usables with Dom addEventListener?

送分小仙女□ 提交于 2019-11-30 18:59:35

问题


I'm using Bootstrap4 alpha in my project, and for some investigations purposes, i'm trying to catch a JQuery event using DOM addEventListener().

The event is fired using the JQuery $("#mypanel").trigger("shown.bs.collapse") function by bootstrap in it's collapse component.

If i try to catch it using the JQuery $("#mypanel").on("shown.bs.collapse", ... ) function, everything works just fine. But if i use $("#mypanel").get(0).addEventListener("shown.bs.collapse", ... ) on the corresponding DOM elements, the event is not "catched"

Are JQuery event system and standard DOM event system are NOT compatibles ?

One thing that make me think they are actualy incompatible, is that if i use the chrome monitorEvents() function to track the "shown.bs.collapse" event, it simply do not appear.

Any feedback about that is welcome !!

Thanks a lot !

Clément


回答1:


No, you can't use jQuery custom events with the regular JavaScript event engine.

Think of the jQuery event system as an extension of the standard DOM event system. jQuery can know about all of the events that the browser raises, because it can create actual event handlers for it. It can also have its own custom events because when you call .trigger('your.custom.event') jQuery can first check for its own stored event handlers for that (custom) event, before raising an actual browser event.



来源:https://stackoverflow.com/questions/34089457/are-jquery-events-usables-with-dom-addeventlistener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!