Add event handler for body.onload by Javascript within part

body.addEventListener(“load”, init(), false); That init() is saying run this function now and assign whatever it returns to the load event. What you want is to assign the reference to the function, not the result. So you need to drop the (). body.addEventListener(“load”, init, false); Also you should be using window.onload and not body.onload addEventListener is … Read more

Is DOMContentLoaded event EXACTLY the same as jQuery’s .ready() function?

Assuming browser that supports the event: The real event can support any document. jQuery will only use the document it was loaded in, no matter what you pass to it. jQuery will fire the event asynchronously even if the event has already happened. Attaching ‘DOMContentLoaded’ event will do nothing if the event has already happened. … Read more

Add a long press event in React

I’ve created a codesandbox with a hook to handle long press and click. Basically, on mouse down, touch start events, a timer is created with setTimeout. When the provided time elapses, it triggers long press. On mouse up, mouse leave, touchend, etc, the timer is cleared. useLongPress.js import { useCallback, useRef, useState } from “react”; … Read more

Storage event not firing

As others in the answers noted, the storage event only get picked up (by the listener) if the localStorage was changed in another browser’s tab/window (of the same app), but not within the context of the current tab. Detect storage changes in the current tab: window.addEventListener(‘storage’, console.log) window.localStorage.setItem(‘test’, ‘123’) window.dispatchEvent( new Event(‘storage’) ) // <—– … Read more

AngularJS – multiple ng-click – event bubbling

This solution worked for me (I’m only supporting recent browsers, so I tried to modify the code to be more retro-compatible): HTML: <li ng-repeat=”item in items” ng-click=”showItem(item)”> <h3>{{item.title}}</h3> <button ng-click=”remove(item, $event)”>Remove</button> </li> Scripts: function remove(item, $event) { // do some code here // Prevent bubbling to showItem. // On recent browsers, only $event.stopPropagation() is needed … Read more