We help IT Professionals succeed at work.

help with Javascript

HLRosenberger
on
Can anyone tell me what this line of code does:

var src = window.event != window.undefined ? window.event.srcElement : evt.target;
Comment
Watch Question

Chris AshcraftSenior Analyst - Technology
BRONZE EXPERT
Commented:
This line is assigning the event source element to the src variable. It it formatted this way for browser compatability. window.event.srcElement is only valid with Internet Explorer. For other browsers it will not be defined and evt.target is used.

It uses the javascript ternary operator, which equates to the following if block..

if (window.event != window.undefined) {   //IE
   var src = window.event.srcElement;
} else {  //Other Browser
   var src = evt.target;
}
Analyst developer
BRONZE EXPERT
Commented:
micropc1 is right

Since the variable evt is available the statement can be reduced to this
var src = evt.srcElement || evt.target;

Open in new window

Author

Commented:
Thanks so much..

Explore More ContentExplore courses, solutions, and other research materials related to this topic.