www.webdeveloper.com
Results 1 to 3 of 3

Thread: getElementById question

  1. #1
    Join Date
    May 2013
    Posts
    2

    getElementById question

    Hello. I am looking at the following tutorial:

    <!DOCTYPE html>
    <html>
    <body>
    <script>
    function changeImage()
    {
    element=document.getElementById('myimage')
    if (element.src.match("bulbon"))
    {
    element.src="pic_bulboff.gif";
    }
    else
    {
    element.src="pic_bulbon.gif";
    }
    }
    </script>

    <img id="myimage" onclick="changeImage()"
    src="pic_bulboff.gif" width="100" height="180">

    <p>Click the light bulb to turn on/off the light</p>

    </body>
    </html>

    What I don't understand is this line:
    element=document.getElementById('myimage')

    Where does "myimage" come from? Is "myimage" the name of a file? Is "myimage" the name of an object that I have to define somewhere? I assume that "pic_bulboff.gif" is the name of a file that should be kept in the same directory as the web page.

    However, I would think the tutorial would do a better job of explaining where all these things come from. Anyone know of a better tutorial?

  2. #2
    Join Date
    May 2013
    Posts
    2
    I am an idiot. Never mind.

    I missed the definition right under the script. Duh!

    How do I delete this thread?

  3. #3
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    Quote Originally Posted by monkeys4freedom View Post
    ...I missed the definition right under the script...
    ... and the [code][/code] tags
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles