Solved

help with Javascript

Posted on 2012-03-14
3
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

617 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