Creation of new event handler from a function in JavaScript

Creating a dyanmic event handler in the Javascript function is quite easy. JavaScript has an inbuilt function ‘addEventListener’ which creates a new event handler.

The syntax of the function is



element.addEventListener( type, listener, useCapture);

type : Representing the type of event being handled.
listener : The listener is the method or function which is called when the event occurs. Preferably the function be an inline function.
useCapture : The value of this parameter is either true or false. When useCapture is assigned true the method/function is called after the creation of the event handler. Otherwise the event is called only at the time, when it is triggered.

An example is given below

td.addEventListener(“click”, function() { alert(“Simple Example”); }, false);

For more reference click here

Leave a Reply

Your email address will not be published. Required fields are marked *