Solved

help with Javascript

Posted on 2012-03-14
3
181 Views
Last Modified: 2012-03-14
Can anyone tell me what this line of code does:

var src = window.event != window.undefined ? window.event.srcElement : evt.target;
0
Comment
Question by:HLRosenberger
3 Comments
 
LVL 7

Assisted Solution

by:micropc1
micropc1 earned 250 total points
ID: 37721629
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
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 250 total points
ID: 37722128
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
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 37722347
Thanks so much..
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question