SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    am i interptreting this code correctly?

    HI,

    Ive just started reading the sitepoint book modern web design using dom and javascript. It seems very good and although ive never touched on programming before im understanding it.

    I have a question about some of the code. IM at a stage in the book where its telling you how you can get elements from the tree ( using id and tag name) Theres this bit of code:

    Code:
    var all_links = document.getElelmentByTagName ('a');
    Var sitepoint_link = all_links [0];
    I understand what its doing in that its calling all elements that have a tag name of a. An array is returned with the first element in the tree being assinged a zero and incrementing up with every additional a tag.

    What i dont think i get is the second line. Is this merely assigning the first entry in the all_links array a variable of sitepoint_link? Its not very clear in the book.

    Is it like creating a reference to that first entry in the array?

  2. #2
    malloc
    Join Date
    Nov 2006
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, sitepoint_link is being assigned from the first element of the all_links array.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Location
    DK
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Page 19 I can see...

    The code:
    Code:
    var all_links = document.getElementsByTagName('a');
    var sitepoint_link = all_links[0];
    I have corrected a few misspellings that will create errors when run. Remember too, JS is case sensitive: Var and var is not the same...

    Line 2: Yes, you got it right.

    If you find that Modern web design using dom and javascript is a good book, I guess you will find The Javascript Anthology 101 essential tips... very interesting, too. Sitepoint again!

    Good luck with JS, a never ending journey :-)

    Michael

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well thanks guys! I might just check that other book out also


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •