I want to call an onblur
on div
. Not sure how to get it done.
Tried this:
div onblur="javascript:callme()"
but it didn't work
The onblur attribute fires the moment that the element loses focus. Onblur is most often used with form validation code (e.g. when the user leaves a form field). Tip: The onblur attribute is the opposite of the onfocus attribute.
If the element that has the onBlur effect and tabindex is created onClick of another element, it does not automatically gets focus when it appears. Thus, you may need to focus it using element. focus() after creating the element.
Definition and Usage Tip: The onblur event is the opposite of the onfocus event. Tip: The onblur event is similar to the onfocusout event. The main difference is that the onblur event does not bubble. Therefore, if you want to find out whether an element or its child loses focus, you could use the onfocusout event.
The HTMLElement. blur() method removes keyboard focus from the current element.
For blur
event to fire on an element, the element needs to receive focus first. But <div>
elements do not receive focus by default.
You can add tabindex="0"
or contentEditable
to your div so it will receive focus.
See it in action: http://jsfiddle.net/t25rm/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With