Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

help with Javascript

Can anyone tell me what this line of code does:

var src = window.event != window.undefined ? window.event.srcElement : evt.target;
0
HLRosenberger
Asked:
HLRosenberger
2 Solutions
 
micropc1Commented:
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;
}
0
 
Albert Van HalenCommented:
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

0
 
HLRosenbergerAuthor Commented:
Thanks so much..
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now