unemployment Posted May 20, 2011 Share Posted May 20, 2011 Why won't onblur work? onclick works! var allDivs = document.getElementsByTagName('div'); for (var i=0; i< allDivs.length; i++) { if (allDivs[i].className.indexOf('goal_icon_holder') != -1) { allDivs[i].onblur = function() { alert('test'); } allDivs[i].onclick = function() { alert('test'); } } } Quote Link to comment https://forums.phpfreaks.com/topic/236998-onblur-fails-onclick-works/ Share on other sites More sharing options...
requinix Posted May 20, 2011 Share Posted May 20, 2011 DIVs do not have onblur events. Quote Link to comment https://forums.phpfreaks.com/topic/236998-onblur-fails-onclick-works/#findComment-1218189 Share on other sites More sharing options...
unemployment Posted May 20, 2011 Author Share Posted May 20, 2011 DIVs do not have onblur events. AHHHHH..... GEEZ Well... thank you for pointing that out. Basically, I have a div wrapper around a link. When the link is pressed a drop down menu is display. When I click away from the menu I want the menu to disappear. I can't have an onblur on the link because then I can never select the option in the menu. How should I go about making this work? Quote Link to comment https://forums.phpfreaks.com/topic/236998-onblur-fails-onclick-works/#findComment-1218193 Share on other sites More sharing options...
requinix Posted May 20, 2011 Share Posted May 20, 2011 I'm not sure. This is a bit complicated, but var closemenu = null; // for each appropriate div { div.onmouseover = function() { closemenu = null; }; div.onmouseout = function() { closemenu = this; }; // } document.onclick = function() { if (closemenu != null) { // closemenu is the to hide closemenu = null; } }; The div.onblur stuff is actually document.click, but because of the closemenu object (which is only set when the mouse has left the div) it won't really do anything until it is supposed to. Quote Link to comment https://forums.phpfreaks.com/topic/236998-onblur-fails-onclick-works/#findComment-1218260 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.