jQuery – Trigger event when an element is removed from the DOM

You can use jQuery special events for this. In all simplicity, Setup: (function($){ $.event.special.destroyed = { remove: function(o) { if (o.handler) { o.handler() } } } })(jQuery) Usage: $(‘.thing’).bind(‘destroyed’, function() { // do stuff }) Addendum to answer Pierre and DesignerGuy’s comments: To not have the callback fire when calling $(‘.thing’).off(‘destroyed’), change the if condition … Read more

jQuery .live() vs .on() method for adding a click event after loading dynamic html

If you want the click handler to work for an element that gets loaded dynamically, then you set the event handler on a parent object (that does not get loaded dynamically) and give it a selector that matches your dynamic object like this: $(‘#parent’).on(“click”, “#child”, function() {}); The event handler will be attached to the … Read more

When a ‘blur’ event occurs, how can I find out which element focus went *to*?

2015 answer: according to UI Events, you can use the relatedTarget property of the event: Used to identify a secondary EventTarget related to a Focus event, depending on the type of event. For blur events, relatedTarget: event target receiving focus. Example: function blurListener(event) { event.target.className=”blurred”; if(event.relatedTarget) event.relatedTarget.className=”focused”; } [].forEach.call(document.querySelectorAll(‘input’), function(el) { el.addEventListener(‘blur’, blurListener, false); }); … Read more

How to prevent ENTER keypress to submit a web form?

[revision 2012, no inline handler, preserve textarea enter handling] function checkEnter(e){ e = e || event; var txtArea = /textarea/i.test((e.target || e.srcElement).tagName); return txtArea || (e.keyCode || e.which || e.charCode || 0) !== 13; } Now you can define a keypress handler on the form: <form […] onkeypress=”return checkEnter(event)”> document.querySelector(‘form’).onkeypress = checkEnter;

Detecting Browser Autofill

The problem is autofill is handled differently by different browsers. Some dispatch the change event, some don’t. So it is almost impossible to hook onto an event which is triggered when browser autocompletes an input field. Change event trigger for different browsers: For username/password fields: Firefox 4, IE 7, and IE 8 don’t dispatch the … Read more

Global Events in Angular

There is no equivalent to $scope.emit() or $scope.broadcast() from AngularJS. EventEmitter inside of a component comes close, but as you mentioned, it will only emit an event to the immediate parent component. In Angular, there are other alternatives which I’ll try to explain below. @Input() bindings allows the application model to be connected in a … Read more

jQuery ‘input’ event

Occurs when the text content of an element is changed through the user interface. It’s not quite an alias for keyup because keyup will fire even if the key does nothing (for example: pressing and then releasing the Control key will trigger a keyup event). A good way to think about it is like this: … Read more

Angular 2 Hover event

If you want to perform a hover like event on any HTML element, then you can do it like this. HTML <div (mouseenter) =”mouseEnter(‘div a’) ” (mouseleave) =”mouseLeave(‘div A’)”> <h2>Div A</h2> </div> <div (mouseenter) =”mouseEnter(‘div b’)” (mouseleave) =”mouseLeave(‘div B’)”> <h2>Div B</h2> </div> Component import { Component } from ‘@angular/core’; @Component({ moduleId: module.id, selector: ‘basic-detail’, templateUrl: … Read more

C# Events and Thread Safety

The JIT isn’t allowed to perform the optimization you’re talking about in the first part, because of the condition. I know this was raised as a spectre a while ago, but it’s not valid. (I checked it with either Joe Duffy or Vance Morrison a while ago; I can’t remember which.) Without the volatile modifier … Read more

Which Python packages offer a stand-alone event system? [closed]

PyPI packages As of January 2022, these are the event-related packages available on PyPI, ordered by most recent release date. pluggy 1.0.0: August 2021 pymitter 0.3.1: June 2021 zope.event 4.5.0: Sept 2020 python-dispatch 0.1.31: Aug 2020 RxPy3 1.0.1: June 2020 Louie 2.0: Sept 2019 PyPubSub 4.0.3: Jan 2019 pyeventdispatcher 0.2.3a0: 2018 buslane 0.0.5: 2018 PyPyDispatcher … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)