How to detect if a click() is a mouse click or triggered by some code?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use the
whichproperty of the event object. It should beundefinedfor code-triggered events:Here’s a working example of the above.
Update based on comments
Pressing the Enter key when an
inputelement has focus can trigger theclickevent. If you want to distinguish between code-triggered clicks and all other clicks (mouse or keyboard triggered) then the above method should work fine.