HTML input file selection event not firing upon selecting the same file

Set the value of the input to null on each onclick event. This will reset the input‘s value and trigger the onchange event even if the same path is selected. var input = document.getElementsByTagName(‘input’)[0]; input.onclick = function () { this.value = null; }; input.onchange = function () { console.log(this.value); }; <input type=”file” value=”C:\fakepath”> Note: It’s … Read more

JavaScript click event listener on class

This should work. getElementsByClassName returns an Array-like object (see below) of the elements matching the criteria. var elements = document.getElementsByClassName(“classname”); var myFunction = function() { var attribute = this.getAttribute(“data-myattribute”); alert(attribute); }; for (var i = 0; i < elements.length; i++) { elements[i].addEventListener(‘click’, myFunction, false); } jQuery does the looping part for you, which you need … Read more

How to display a confirmation dialog when clicking an link?

Inline event handler In the most simple way, you can use the confirm() function in an inline onclick handler. <a href=”https://stackoverflow.com/questions/10462839/delete.php?id=22″ onclick=”return confirm(‘Are you sure?’)”>Link</a> Advanced event handling But normally you would like to separate your HTML and Javascript, so I suggest you don’t use inline event handlers, but put a class on your link … Read more

Unable to understand useCapture parameter in addEventListener

Events can be activated at two occasions: At the beginning (“capture”), and at the end (“bubble”). Events are executed in the order of how they’re defined. Say, you define 4 event listeners: window.addEventListener(“click”, function(){console.log(1)}, false); window.addEventListener(“click”, function(){console.log(2)}, true); window.addEventListener(“click”, function(){console.log(3)}, false); window.addEventListener(“click”, function(){console.log(4)}, true); The log messages will appear in this order: 2 (defined first, … Read more

Stop mouse event propagation

If you want to be able to add this to any elements without having to copy/paste the same code over and over again, you can make a directive to do this. It is as simple as below: import {Directive, HostListener} from “@angular/core”; @Directive({ selector: “[click-stop-propagation]” }) export class ClickStopPropagation { @HostListener(“click”, [“$event”]) public onClick(event: any): … Read more

Pass mouse events through absolutely-positioned element

pointer-events: none; Is a CSS property that makes events “pass through” the HTML-element to which the property is applied. It makes the event occur on the element “below”. See for details: https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events It is supported by almost all browsers, including IE11; global support was ~98.2% in 05/’21): http://caniuse.com/#feat=pointer-events (thanks to @s4y for providing the link … Read more

Prevent form submission on Enter key press

if(characterCode == 13) { // returning false will prevent the event from bubbling up. return false; } else{ return true; } Ok, so imagine you have the following textbox in a form: <input id=”scriptBox” type=”text” onkeypress=”return runScript(event)” /> In order to run some “user defined” script from this text box when the enter key is … Read more

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