Reputation: 6246
I want to trigger one handler when an input field is clicked, and another handler when it is deselected (i.e. if someone clicks outside of the field). Is there a way to accomplish this?
The click handler is simple enough:
input onClick={props.clicked}
Is it possible to create an "unclick" handler?
Note: Re-asking/re-answering the question from here, because that question had a React tag, and was consequently tagged as a duplicate because the question had been asked in the context of React, but I was equally curious about how to solve the problem in a non-React context. This question deserves more visibility as a non-duplicate for those looking to solve the problem outside of React.
Upvotes: 0
Views: 123
Reputation: 6246
Answer: The onBlur
event solves this problem. Thanks to Ran Marciano: HTML onUnclick handler?
Upvotes: 1