The following code works in a browser:
var event = event || window.event;
var eTarget = event.target || event.srcElement;
var eTargetId = eTarget.id;
When I change it to
var eTargetId = event.target ? event.target.id : event.srcElement.id;
it works, too.
When I change the code to
var eTargetId = event.target.id || event.srcElement.id;
it doesn't work in IE 678. I get the following error:
SCRIPT5007:Object expected.
Why is this happening?
This is likely happening because event.target
is null but event
is not. Your first two attempts use short-circuiting to prevent further evaluation if event.target
is null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With