I am using the event listener structure like below to do some stuff when the input box loses focus.
But it won’t work. What event should I listen to, to get the moment the input box loses the cursor inside it (i.e. user clicks outside of it)?
document.getElementById('div inside which input is located')
.addEventListener( 'blur', function(e){
if(event.target.className=='editInput'){
doStuff(event.target);
}
} , false );
The correct event is onBlur. Look at this code:
It works and prints the content of the input when it loses focus. Maybe your error is that you attached the event to the div and not to the input?