Lets say there is a textbox and a button. On the click of button a function is executed, and on the focusout of textbox, the button is clicked. What I wanna know is, is there a way, I can determine that weather the user clicked the button, or it was triggered by focusout event of textbox, so that I may do some custom work in the click event, if it was triggered by focusout of textbox?
I could write some code, but I don’t even have any idea where to begin with, I know the jQuery event and event.which property, but I wonder if it/they could be useful in this situation?
This depends on how you’re triggering the function from the
textareablurevent, if you’re simply triggering theclickevent using the following approach:Then I’d suggest evaluating the
originalEventobject to see what the original event was (if there was nooriginalEventthen the function was called by a programmaticclickevent, with jQuery; whereas if theoriginalEvent.typeevaluates toclickthen the button must have been clicked.JS Fiddle demo.
If, however, you’re using something like the following (simply calling the same function from a different place):
Then I’d recommend either directly assessing
e.targetore.type:JS Fiddle demo.