IMG Javascript question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Kaplan

    IMG Javascript question

    So just started playing with Javascript, and my first run at making three
    step buttons came out just fine. But I do have a general question.

    In my book's example in the HTML script the IMG tags have the button's
    settnigs for Width, Height, Border (0), and even grant each button an "id".

    The "id" label is not used in the Javascript, so I was wondering if it and
    the other items listed above MUST be in the HTML code, or does the book have
    it in there just to be all proper like?

    Many thanks


  • SAM

    #2
    Re: IMG Javascript question

    Daniel Kaplan a écrit :
    So just started playing with Javascript, and my first run at making three
    step buttons came out just fine. But I do have a general question.
    >
    In my book's example in the HTML script the IMG tags have the button's
    settnigs for Width, Height, Border (0), and even grant each button an "id".
    >
    The "id" label is not used in the Javascript, so I was wondering if it and
    the other items listed above MUST be in the HTML code, or does the book have
    it in there just to be all proper like?
    certainly in next pages of your book they will learn to you how to use
    this ID in JS.

    For the moment, notice that you can have only one ID of same name in a page
    (2 or more identical ids is forbidden - the JS will have to be abble to
    find the element (object?) by its ID, with several clones it will
    retreive only the 1rst of them)


    Of course, if these IDs are not used you can delette them
    (be sure they are not used by CSS)
    (take care your exercice will be used in next ones and probably there
    the IDs will get sens)


    width, height, border can be fixed by CSS.

    Get used to write all your code (even in HTML) in lowercase
    (Height -height - onMouseOver -onmouseover)
    If the HTML is not case sensitive, the JS it is.

    If you'll do :

    Code:
    <script type="text/javascript">
    function hello() { alert('hello');}
    function init() {
    document.images[0].onClick = hello;
    }
    window.onload = init;
    </script>
    that will not work because in JS it is : onclick


    Code:
    <script type="text/javascript">
    function hello() { alert('hello');}
    function init() {
    if(document.images && document.images.length>0)
    {
    document.images[0].omouseover = hello;
    }
    }
    window.onload = init;
    </script>
    --
    sm

    Comment

    Working...