I have a form with on blur listener, when I click outside the form and the blur triggered, can I get the element that was clicked on?
Asked
Active
Viewed 679 times
0
-
Not without a `click` listener as well. – adeneo Nov 02 '16 at 20:35
-
http://stackoverflow.com/a/121708/1640090 – vbguyny Nov 02 '16 at 20:45
1 Answers
0
You can always get the element that triggered any event with event.target
, but you need to set up an event handler for that event. As @adeneo said, you'd need to set up a click
event handler that would fire no matter where you might click. You could do this by setting the handler on document.click
. However, this will fire even if you have clicked inside your form. You'd need to do some validation on the clicked element to be sure it's one that you are interested in.

Scott Marcus
- 64,069
- 6
- 49
- 71
-
[Here's a fiddle](https://jsfiddle.net/kvawtf4a/) (open your console developer tool) – Robiseb Nov 02 '16 at 21:20