Jump to content

Onblur Fails... Onclick works?!


unemployment

Recommended Posts

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

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.