Solved

help with Javascript

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sums of coloumns in html/java 15 64
Elegant Way to Include Query String When it exists? 4 42
jQuery not working on ELSE... why? 2 19
Wrapper for APPs 9 25
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

929 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

10 Experts available now in Live!

Get 1:1 Help Now