Concerning Event Handlers (Full Version)

All Forums >> [Web Development] >> General Web Development



Message


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>




jaybee -> RE: Concerning Event Handlers (6/8/2008 5:36:52)

What exactly are you trying to do? Expand and contract menus?




aaronfjerstad -> RE: Concerning Event Handlers (6/9/2008 0:27:09)

That is essentially the idea. I am trying to add menu function to a fluid layout. This was the solution that I devised. Unfortunately, I have not been able to force the closure of the menu upon exit.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
3.320313E-02