How to decide if a parameter is the click event

Posted by sameold on Stack Overflow See other posts from Stack Overflow or by sameold
Published on 2012-06-02T03:41:52Z Indexed on 2012/06/02 4:40 UTC
Read the original article Hit count: 176

Filed under:
|

I have a function which can be called by either a click event or directly. When I call it directly, I need pass it a data parameter, so I've defined the function to accept a parameter to account for the direct call with the parameter.

function myFunc(param){

}

Within the function, I need to differentiate whether the function was called directly or from the click event, so what I thought I could simply check if param is set. If it's set, then the function is called directly. If it's not set, then it's called from the click event.

The problem is that a click event by default passes an event object. So even when the function is called by the click event, param won't be null.

So is there a way to check whether the param passed is the click event?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery