Owyn
Owyn

Reputation: 673

javascript: html inline events - get the event name from its calling

<div onclick="func(this)" onmouseover="func(this)">

is there a way to know which way (by click or mouseover) func() was called from code above without changing it (the code above)?

Upvotes: 0

Views: 40

Answers (2)

bp4D
bp4D

Reputation: 961

event.type gives you the event name. For this work in FF you need to pass event as as the input to the method

jsfiddle link here

<div onclick="javascript:func(event,this)" onmouseover="javascript:func(event,this)"> <span>Hi</span> </div>

Upvotes: 0

Amit Joki
Amit Joki

Reputation: 59232

Yes. In func(), you can do:

event.type

but it won't work in FireFox as it isn't exposed to the global scope as opposed to others.

Upvotes: 4

Related Questions