Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.