Temporary Onmouseover

Posted by 2x2p1p on Stack Overflow See other posts from Stack Overflow or by 2x2p1p
Published on 2010-05-16T15:37:08Z Indexed on 2010/05/16 15:40 UTC
Read the original article Hit count: 283

Filed under:
|

Hi guys :)

Css "over" selector applys a temporary style to an element, it isn't definitive:

div:hover {
 background-color: red;
}

I can use the same thing with javascript but it is a bit complicate and impossible for several elements:

var elem = document.getElementByTagName ("div")[0];

elem.onmouseover = function () {
 this.style.backgroundColor = "red";
}

elem.onmouseout = function () {
 this.style.backgroundColor = "transparent";
}

There is a better way ? Something like this:

document.getElementByTagName ("div")[0].ontemporarymouseover = function () { // LoL
 this.style.backgroundColor = "red";
}

Thanks

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about onmouseover