I'm listening to the onFocus
and to onClick
events on the same input-element. The onFocus
should always set a boolean to true
and the onClick
event handler should toggle this boolean.
But on a click both events are fired with the onFocus
at first, so the boolean is being set to true
first and then toggled by the onClick
. How can I change this behaviour?
I tried to use stopPropagation
inside the onClick
event handler. Also setting a isClicked
flag did not help. (Probably because both events are fired at the same time) (see JSFiddle)
let input = document.getElementById("input");
let isOpen = false
input.onclick = () => {
isOpen = !isOpen
}
input.onfocus = () => {
isOpen = true
}
input.onblur = () => {
isOpen = false
}
JSFiddle: http://jsfiddle.net/coh29gwe/7/
At the first click on the input the isOpen
flag should be true but is false.