|
aaronfjerstad -> Concerning Event Handlers (6/3/2008 17:00:28)
|
I am having a problem reguarding the assignment of event handlers. My code creates a box 10 pixels above and to the left of the point clicked on a DIV. This works fine. The problem occurs when I attempt to assign an event handler to the onMouseOut event of the newly created DIV. Can anyone help me? Here is the isolated code: <style> div.myDiv { width:200; height:200; overflow:hidden; background:rgb(0,122,122); } div.menuDiv { width:100; height:50; background:rgb(255,0,0); position:absolute; } </style> <script> var posx, posy, menuDiv; function menu() { posx = event.x; posy = event.y; menuDiv = document.createElement('div'); menuDiv.className = "menuDiv"; menuDiv.style.top = posy - 10; menuDiv.style.left = posx - 10; <!---Offending Code---!> menuDiv.setAttribute("onMouseOut", "closeMenu()"); <!---This should cause the DIV to close.---!> <!---End Offending Code---!> menuDiv = document.getElementById('myDiv').appendChild(menuDiv); } function closeMenu() { menuDiv.innerHTML = ""; menuDiv.removeNode(); } </script> <div onClick = "menu()" id = "myDiv" name = "myDiv" class = "myDiv"><br></div>
|
|
|
|