why onblur Event Dosent Work For Div Element ???????????
-
Hello I have a Project that Use Very Div Element And Onblur Event In its. Because Of Security Reason We Switch From a version of JQuery To another . But We Face With This Problem : onblur Event dont Fire In Div Element But it Fire in input elements Like Textbox!!!!! and also onfocusout Event Fire in dive but i dont want use this.
any help To solve this Problem can be useful thanks in advance
-
Hello I have a Project that Use Very Div Element And Onblur Event In its. Because Of Security Reason We Switch From a version of JQuery To another . But We Face With This Problem : onblur Event dont Fire In Div Element But it Fire in input elements Like Textbox!!!!! and also onfocusout Event Fire in dive but i dont want use this.
any help To solve this Problem can be useful thanks in advance
Literally the first result on Google for "html div onblur":
http://stackoverflow.com/questions/18504139/div-onblur-function[^]
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 addtabindex="0"
orcontentEditable
to yourdiv
so it will receive focus.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Literally the first result on Google for "html div onblur":
http://stackoverflow.com/questions/18504139/div-onblur-function[^]
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 addtabindex="0"
orcontentEditable
to yourdiv
so it will receive focus.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
ok but focusout event fire without set tabIndex=0 to div element , and this means that div has focus in this scenario!!!! i set "tabIndex=0" to div element for fire onblur and doesn't work!
The blur event fires when focus is lost. By default, a div element cannot have the focus in the first place so it can not be lost. If you give the div a tabindex attribute, it will be able to accept focus:
Test content here
then attach focus and blur event handlers:
document.getElementById("divid").onfocus = function() {
alert('focus is hit');
}
document.getElementById("divid").onblur = function() {
alert('blur is hit');
}Hope this helps !! Regards, Praneet.