Can someone explain this code line to me?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • effendi@epitome.com.sg

    #1

    Can someone explain this code line to me?

    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=docume nt.getElementBy ID?
    document.getEle mentById("slide r-1"): null;

    Question 1: What is the function of the "?" mark after the
    document.getEle mentByID
    Question 2: What is the reason for including ": null"
    and Question 3: Can't this be done just by simply using
    "document.getEl ementById("slid er-1")"?

    Thanks in advance.

  • Evertjan.

    #2
    Re: Can someone explain this code line to me?

    wrote on 03 apr 2005 in comp.lang.javas cript:
    [color=blue]
    > 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=docume nt.getElementBy ID?
    > document.getEle mentById("slide r-1"): null;
    >
    > Question 1: What is the function of the "?" mark after the
    > document.getEle mentByID
    > Question 2: What is the reason for including ": null"[/color]

    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

    =============== =============== ===========
    [color=blue]
    > and Question 3: Can't this be done just by simply using
    > "document.getEl ementById("slid er-1")"?[/color]

    (document.getEl ementByID)

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

    var sliderE1 = document.getEle mentById("slide r-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=javasc ript.tutorial>

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

    Comment

    Working...