SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Question re: targeting objects with getElementById

    I'm referencing the object or object handle incorrectly, is that what 'this.' is called ?
    I put together a super simple page demonstrating my ravings and my question using spinning colored boxes.
    LINK (see source)

    #greenbox and #greybox essentially have the same code.
    One uses this. and the other uses the var orangehandle

    Many thanks in advance

  2. #2
    SitePoint Enthusiast aufshebung's Avatar
    Join Date
    May 2012
    Location
    Santa Fe, NM
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is you're trying to get the element by its ID... before it's been created.

    The absolute quickest fix is to just put the <script> tag after the #orangebox element:

    HTML Code:
    <div id="orangebox"></div>
    
    <script type="text/javascript">
        var orangevar = document.getElementById("orangebox");
    </script>

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    thank you!
    TIL something about parsing


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
  •