Sign in to follow this  
Followers 0
diox76

addEventListener method

2 posts in this topic

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.

:)

Edited by diox76

Share this post


Link to post
Share on other sites

Yes, any string will work, literal or not.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0