zanhtet
zanhtet

Reputation: 2050

window.event.srcelement not working in firefox

 _eventButtonElement = window.event.srcElement;

How can I solve that in firefox?

Upvotes: 4

Views: 8441

Answers (3)

vbanuelo
vbanuelo

Reputation: 21

This should work: _eventButtonElement = window.event.srcElement || window.event.originalTarget;

originalTarget is the firefox equivalent to srcElement.

Upvotes: 2

qwertymk
qwertymk

Reputation: 35276

Firefox uses an event argument that gets passed into an event function

Change your code from this:

window.onload = function() {
    //CODE
    _eventButtonElement = window.event.srcElement;
    //CODE
};

To this:

window.onload = function(e) {
    //CODE
    _eventButtonElement = window.event.srcElement || e.target;
    //CODE
};

Upvotes: 10

Chandu
Chandu

Reputation: 82903

One of the cross Browser issues. Use this:

var evnt = event || window.event;
_eventButtonElement  = evnt.target || evnt.srcElement;

Upvotes: 5

Related Questions