have dumb question.
Here I've got three events calling the same function, connected to the same <div>
:
<html>
<head>
<script type='text/javascript'>
function universal_action_handler( event ) {
var eType = event.type;
var eTarget = event.target || event.srcElement;
console.log( "Captured Event, type=", eType, ", target=", eTarget );
if( 'mouseover' == eType ) {
console.info( "onMouseOver: set background color to red." );
eTarget.style.backgroundColor = 'red';
eTarget.style.fontSize = '';
}
if( 'mouseout' == eType ) {
console.info( "onMouseOut: set background color to transparent." );
eTarget.style.backgroundColor = 'transparent';
eTarget.style.fontSize = '';
}
if( 'click' == eType ) {
console.info( "click!" );
eTarget.style.fontSize = 'larger';
}
}
</script>
</head>
<body>
<div style='border: 1px dashed red; display: inline-block;'
onClick="universal_action_handler(event);"
onMouseOver="universal_action_handler(event);"
onMouseOut="universal_action_handler(event);">Click me!</div>
</body>
</html>
I have onClick=''
, onMouseOver=''
, and onMouseOut=''
, all connected to the same <div>
, and all calling the same function. If I want to add an event, I have to add an onEventThingy=''
and call the same universal action handler function above. Inside the function, it decides what kind of event (event.type
) and takes action.
Is there an onAnything=''
event that I can use to call the universal function for any event which may happen to that <div>
?