Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div - onblur function

Tags:

html

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

like image 256
user2357770 Avatar asked Aug 29 '13 06:08

user2357770


People also ask

What does Onblur function do?

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.

Why is Onblur not fired?

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.

What is Onfocus and Onblur?

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.

What is a blur () in HTML?

The HTMLElement. blur() method removes keyboard focus from the current element.


1 Answers

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/

like image 106
Strelok Avatar answered Sep 22 '22 13:09

Strelok