Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Can someone explain this code line to me?

Reply
Thread Tools

Can someone explain this code line to me?

 
 
effendi@epitome.com.sg
Guest
Posts: n/a
 
      04-03-2005
Hi everyone, I am relatively new to JS and I am hoping someone could
tell me what this line of codes mean. This was written by some
brilliant guys at webfx and I am trying to understand some of their
codes.

To begin with I don't understand how this variable is set.

var sliderE1=document.getElementByID?
document.getElementById("slider-1"): null;

Question 1: What is the function of the "?" mark after the
document.getElementByID
Question 2: What is the reason for including ": null"
and Question 3: Can't this be done just by simply using
"document.getElementById("slider-1")"?

Thanks in advance.

 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      04-03-2005
wrote on 03 apr 2005 in comp.lang.javascript:

> Hi everyone, I am relatively new to JS and I am hoping someone could
> tell me what this line of codes mean. This was written by some
> brilliant guys at webfx and I am trying to understand some of their
> codes.
>
> To begin with I don't understand how this variable is set.
>
> var sliderE1=document.getElementByID?
> document.getElementById("slider-1"): null;
>
> Question 1: What is the function of the "?" mark after the
> document.getElementByID
> Question 2: What is the reason for including ": null"


var condition = false
var a = (condition) ? "This is true" : "This however is false"
alert(a)

will show: This however is false

var condition = true
var a = (condition) ? "This is true" : "This however is false"
alert(a)

will show: This is true

=========================================

> and Question 3: Can't this be done just by simply using
> "document.getElementById("slider-1")"?


(document.getElementByID)

is only true in browsers that support it.
in other [read older] browsers:

var sliderE1 = document.getElementById("slider-1")

would give an error and the js would stop.

========================================

Your first questions are so basic,
that I suppose you did not read any javascript tutorial before asking.

<http://www.google.com/search?q=javascript.tutorial>

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can someone explain this code? Angus C++ 3 06-23-2008 05:42 PM
can someone explain line 7 and 8 of the insertion sort Troy Java 0 02-16-2008 04:50 PM
Can someone please explain the output of this code? Aarti C++ 3 07-27-2007 03:34 PM
Can someone explain this code to me pandu345@yahoo.com Java 2 11-07-2006 10:42 AM
Re: please can someone explain the following code. suzy ASP .Net 3 07-31-2003 02:07 PM



Advertisments