What are passive event listeners?

While working around to boost performance for progressive web apps, I came across a new feature Passive Event Listeners and I find it hard to understand the concept. What are Passive Event Listeners and what is the need to have it in our projects? Best Answer It enables developers to opt-in to better scroll performance by eliminating the … Read more

JavaScript click event listener on class

I’m currently trying to write some JavaScript to get the attribute of the class that has been clicked. I know that to do this the correct way, I should use an event listener. My code is as follows: var classname = document.getElementsByClassName(“classname”); var myFunction = function() { var attribute = this.getAttribute(“data-myattribute”); alert(attribute); }; classname.addEventListener(‘click’, myFunction(), … Read more

How to display a confirmation dialog when clicking an link?

I want this link to have a JavaScript dialog that asks the user “Are you sure? Y/N”. <a href=”https://stackoverflow.com/questions/10462839/delete.php?id=22″>Link</a> If the user clicks “Yes”, the link should load, if “No” nothing will happen. I know how to do that in forms, using onclick running a function that returns true or false. But how do I … Read more

Unable to understand useCapture parameter in addEventListener

I have read article at https://developer.mozilla.org/en/DOM/element.addEventListener but unable to understand useCapture attribute. Definition there is: If true, useCapture indicates that the user wishes to initiate capture. After initiating capture, all events of the specified type will be dispatched to the registered listener before being dispatched to any EventTargets beneath it in the DOM tree. Events … Read more