addEventListener method in JavaScript Posted February 20, 2017 · Edited February 20, 2017 by diox76 Hi everyone, According to the explanation about this method here, it accepts three parameters: - new event created in runtime; - anonymous (or not) function; - a third parameter (boolean). I would like to know if the first parameter can be a variable such as "newEvent" instead to write as literal ("click")E.g.: function myfunction(myId, newEvent) { document.getElementById(myId).addEventListener(newEvent, function(){ ... }); } Is this possible? My idea is pass a value to my function as parameter to 'addEventListener' method. Thanks in advance. Best regards.
addEventListener method
in JavaScript
Posted · Edited by diox76
Hi everyone,
According to the explanation about this method here, it accepts three parameters:
- new event created in runtime;
- anonymous (or not) function;
- a third parameter (boolean).
I would like to know if the first parameter can be a variable such as "newEvent" instead to write as literal ("click")
E.g.:
function myfunction(myId, newEvent)
{
document.getElementById(myId).addEventListener(newEvent, function(){
...
});
}
Is this possible? My idea is pass a value to my function as parameter to 'addEventListener' method.
Thanks in advance.
Best regards.