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'); } } } 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. 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? 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. Link to comment https://forums.phpfreaks.com/topic/236998-onblur-fails-onclick-works/#findComment-1218260 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.