www.webdeveloper.com
Results 1 to 3 of 3

Thread: A big problem with onmouseover

  1. #1
    Join Date
    Feb 2010
    Posts
    2

    Question A big problem with onmouseover

    I have a code like this:
    Code:
    <script type="text/javascript">
    function wr(){
    	document.getElementsByTagName('body')[0].innerHTML+=1;
    	
    }
    function wr2(){
    	document.getElementsByTagName('body')[0].innerHTML+=2;
    	
    }
    </script>
    </head>
    <body>
    sdsd
    <span onmouseover="wr()" onmouseout="wr2()" id='tex'>aaaa</span>
    ewewe
    </body>
    </html>
    and when I'm moving the mouse on the span, the result is like this:
    sdsd aaaa ewewe 12121212121212121212121212121212121212121212121212121212121212121212

    as if "onmouseover" is the same as "onmousemove"! What can I do with this? THanks!

  2. #2
    Join Date
    Jun 2007
    Posts
    667
    Quote Originally Posted by Teron View Post
    and when I'm moving the mouse on the span, the result is like this:
    sdsd aaaa ewewe 121212121212121212121
    You're re-writing the entire body, which is triggering mouseout then mouseover events. You need to isolate the involved elements:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function wr( elem )
    {
       document.getElementById('theContent').innerHTML+=1;
    }
    function wr2(elem)
    {
      document.getElementById('theContent').innerHTML+=2;	
    }
    </script>
    </head>
    <body>
    sdsd
    <span onmouseover="wr()" onmouseout="wr2()" id='tex'>aaaa</span>
    <div id='theContent'></div>
    </body>
    </html>
    Y_U U_G_A_E_U_ B_S_A_D_

  3. #3
    Join Date
    Feb 2010
    Posts
    2
    Thanks Sterling! It took me hours to realize this problem...

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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