I have a text input and one button of type submit adjacent to the input. I have bound focusout
event-handler to the input and click event-handler to the button. Now when I focus on the input and then press enter
, the focusout
event-handler gets triggered and the buttons-event handler gets triggered. I want to trigger focusout
only when text box focus is lost. What should I do ?
Code :-
<div >
<span>Local Currency: </span>
<input type='text' id='txtFocusElement' />
<button id="btnClickElement" >
<span> Add new line</span>
</button>
</div>
I used selector as:
$("#txtFocusElement").bind("focusout", function() {
console.log('focusout');
})
$("#btnClickElement").bind("click", function() {
console.log('click');
})
and written above code in one function which I call at the time of loading document.
You could try to change the selector to input[type=text]. This will only get triggered when you focus out on a text field.