Difference between document.addEventListener and window.addEventListener?

The document and window are different objects and they have some different events. Using addEventListener() on them listens to events destined for a different object. You should use the one that actually has the event you are interested in. For example, there is a “resize” event on the window object that is not on the … Read more

removeEventListener without knowing the function

getEventListeners(window) will return a map of events and their registered event listeners. So for DOMContentLoaded event for example you can have many event listeners. If you know the index of the listener you want to remove (or if there exists only one), you can do: var eventlistener = getEventListeners(window)[“DOMContentLoaded”][index]; window.removeEventListener(“DOMContentLoaded”, eventlistener.listener, eventlistener.useCapture);

Watch for Dynamically Added Class

Try $(document).ready(function() { var target = $(“#test”).get(0); // create an observer instance var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { // do stuff when // `attributes` modified // i.e.g., alert(mutation.type); target.innerHTML = “class added: ” + “<em>” + target.className + “</em>”; }); }); // configuration of the observer: var config = { attributes: true }; … Read more

Why is Event.target not Element in Typescript?

It doesn’t inherit from Element because not all event targets are elements. From MDN: Element, document, and window are the most common event targets, but other objects can be event targets too, for example XMLHttpRequest, AudioNode, AudioContext, and others. Even the KeyboardEvent you’re trying to use can occur on a DOM element or on the … Read more

eventlisteners using hibernate 4.0 with spring 3.1.0.release?

I had the same frustrating problem. Hibernate 4 appears to have fundamentally changed the way you register for events and the Spring group has not yet caught up. Here’s my annotation-based solution using an init method to register a listener: @Component public class HibernateEventWiring { @Autowired private SessionFactory sessionFactory; @Autowired private SomeHibernateListener listener; @PostConstruct public … Read more

JavaScript custom Event Listener

var evt = document.createEvent(“Event”); evt.initEvent(“myEvent”,true,true); // custom param evt.foo = “bar”; //register document.addEventListener(“myEvent”,myEventHandler,false); //invoke document.dispatchEvent(evt); Here is the way to do it more locally, pinpointing listeners and publishers: http://www.kaizou.org/2010/03/generating-custom-javascript-events/

Android: Difference between onInterceptTouchEvent and dispatchTouchEvent?

The best place to demystify this is the source code. The docs are woefully inadequate about explaining this. dispatchTouchEvent is actually defined on Activity, View and ViewGroup. Think of it as a controller which decides how to route the touch events. For example, the simplest case is that of View.dispatchTouchEvent which will route the touch … Read more

Want to add “addEventListener” on multiple elements with same class [duplicate]

You need to use querySelectorAll which will return a collection.Now use spread operator (three dots) to convert it to array and use forEach .Inside forEach callback add the event listener to it […document.querySelectorAll(‘.breakdown’)].forEach(function(item) { item.addEventListener(‘click’, function() { console.log(item.innerHTML); }); }); <button id=’btn-1′ type=”button” name=”first” class=”breakdown main-text”> Breakdown Start </button> <button id=’btn-2′ type=”button” name=”second” class=”breakdown main-text” … Read more

What are passive event listeners?

Passive event listeners are an emerging web standard, new feature shipped in Chrome 51 that provide a major potential boost to scroll performance. Chrome Release Notes. It enables developers to opt-in to better scroll performance by eliminating the need for scrolling to block on touch and wheel event listeners. Problem: All modern browsers have a … Read more

EventListenerList firing order

Since the documentation for JSlider and JComponent etc don’t mention the order of listener notification, I would hesitate to rely on it, at least without thorough testing on each subsequent version of the JRE. If you really need to rely on the order, consider setting up a chain of listeners, ie Listener one will notify … Read more