Web Analytics Made Easy -
StatCounter Difference Between Onmouseover in Tag and Window:Onload? - CodingForum

Announcement

Collapse
No announcement yet.

Difference Between Onmouseover in Tag and Window:Onload?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Difference Between Onmouseover in Tag and Window:Onload?

    Hi,
    I want to know whether javascript will react differently if I put an img.onmouseover=myfunction() inside window.onload than puting it in html img tag?

    I am trying to use img.onmouseover inside window.onload. For examples, I want some images on the webpage to do something when visitor moves their mouse over it. But I don't want to put onmouseover inside the tag in html and I decided to do it in window.onload for design reason, and I do img.onmouseover=myfunction() in window.onload. I get the img from document.getElementsByTagName('img'), then get the correct img by traversing the tree.

    When I put img.onmouseover=myfunction() inside window.onload, the browser does the thing in myfunction() without having me moving the mouse over the image right at the beginning.

    How can I make it not to run myfunction() right at the start?
    Many thanks.
    Last edited by dealmaker; Aug 3, 2005, 10:20 PM.

  • #2
    when ur assigning event handlers in javascript u've keep in mind that this code actually gets executed...
    so,
    Code:
    img.onmouseover=myfunction();
    this means ur running myfunction and assinging its output to onmouseover

    to actually assign a handler u've to do this
    Code:
    img.onmouseover=myfunction;
    notice the absence of the ()
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

    Comment

    Working...
    X