Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change an onmouseover event using Javascript?

Tags:

javascript

I have an HTML span which changes it's class onmouseover and onmouseout:

<span id="someSpan" class="static" onmouseover="this.className='active'" onmouseout="this.className='static'">Some Text</span>

I want to be able to enable and disable (change) the onmouseover and onmouseout events using a Javascript function called elsewhere on the page. Is this Possible?

like image 632
Trastle Avatar asked Aug 17 '09 13:08

Trastle


2 Answers

Sure.

document.getElementById('someSpan').onmouseover = 
     function() { 
         this.className='newactive'; 
     };
like image 68
Tom Ritter Avatar answered Sep 27 '22 20:09

Tom Ritter


The safe way is to use a Javascript toolkit like Prototype or JQuery.

They all can do things like this easily but it works cross-browser.

For example, here is how you do it in JQuery.

like image 28
Jason Cohen Avatar answered Sep 27 '22 19:09

Jason Cohen