Event handling for a dynamically created element

Dear All,

Please can some one help me with this seemingly unresolvable chicken and egg situation.

Pseudo Code

onmouseover of menu button create drop down menu

add to DOM

addEventListener for new down menu

handle event when mouse over new drop down


So I can create the drop down I can add the event listener
but I cannot code the event handler.

When ever I add the code

newDropDown.onmouseover = function(){
// handle the event here
}

I get error newDropDown not defined. I am assuming that this is because on the first time through the code the dynamically created element.

Sure there must be some way to use the eventlistener that has been added once the new element has been created.

Please can someone point me in the right direction.

Regards

You need to show some not-so-pseudo code.