SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,292
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    why isn't mouseover being registered/called?

    this is a stripped down version of my code to demonstrate a problem i don't know how to solve:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    	<title>Untitled</title>
    </head>
    <body>
    <p>
    <span id="roll">rollover</span>
    </p>
    <script type="text/javascript">
    function Test() { }
    Test.prototype.displayAlert = function(evt) {
    	alert("here");
    }
    function runOnLoad() {
    	var testObject = new Test();
    	var roll = document.getElementById("roll");
    	roll.setAttribute("mouseover", testObject.displayAlert, false);
    }
    if(window.addEventListener)
    	window.addEventListener("load", runOnLoad, false);
    else if (window.attachEvent) window.attachEvent("onload", runOnLoad);
    else window.onload = runOnLoad;
    </script>
    </body>
    </html>
    runOnload() is getting called ok. but then when i roll over the rollover text, its mouseover event's function ( displayAlert() ) isn't called. why?

    thanks.

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,897
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    try

    Code:
    roll.onmouseover = testObject.displayAlert;
    instead of the setAttribute (that doesn't work too well cross-browser)

  3. #3
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,292
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    that did it, thanks.

    i'm using/testing in safari and firefox on a mac; i'm sure they, at least firefox, deal with setAttribute ok? surely firefox is ok with setAttribute? i'm sure i've used that successfully before but i could be wrong.

    so if firefox isn't ok with setAttribute which browsers are?

    thanks.

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,897
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    I believe the whole IE-family doesn't support it (maybe 7 does, not sure).

  5. #5
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by johnyboy View Post
    i'm using/testing in safari and firefox on a mac; i'm sure they, at least firefox, deal with setAttribute ok? surely firefox is ok with setAttribute? i'm sure i've used that successfully before but i could be wrong.

    so if firefox isn't ok with setAttribute which browsers are?
    It's more a question of how 'attribute' is defined, and strictly speaking an event handler need not be regarded as an attribute.
    Tab-indentation is a crime against humanity.

  6. #6
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,292
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    I believe the whole IE-family doesn't support it (maybe 7 does, not sure).
    right, but i'm using firefox so it doesn't add up.

    i've just realised i should have been using addEventListener not setAttribute.

    i knew something else was wrong, couldn't work out what. i know ie doesn't have addEventListener.

    thanks.

  7. #7
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,292
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Logic Ali View Post
    It's more a question of how 'attribute' is defined, and strictly speaking an event handler need not be regarded as an attribute.
    yup i've realised i was making a mistake with that. thanks


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
  •