Solved

help with Javascript

Posted on 2012-03-14
3
176 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now