How HTML attribute onblur
and jQuery .trigger("blur")
event work?
will both events execute like javascript this.trigger("blur")
work first and then HTML attribute onblur
work or only one event will be fired?
I am using onblur
attribute on an input element and in some scenarios I have triggered that event using javascript but my function is executing multiple times. I think the blur event fired two times, so how I can fired it only once?
Here is HTML element.
<input class="form-control"
type="text"
id="ListDisplay"
onblur="changeVal()"
autocomplete="off"
value="${name}"
display="${name}"
/>
Here is the jquery event on which blur triggered. in this showSuggestionListItem is a dynamic dropdown.
$(".showSuggestionListItem").off('mousedown').on('mousedown',
function () {
$('#ListDisplay').trigger("blur");
}
);
Here is changeVal function of onblur.
function changeVal(){
alert('called');
}
elem
? what is. showSuggestionListItem
– epascarellochangeVal
you immediately know what you're doing. If instead you call.blur()
ortrigger("blur")
you have to go throughout the entire codebase to lookup and understand what it's supposed to do and what will happen in return..on('mousedown', changeVal)
is way cleaner than anything else. – Roko C. Buljan