Cssの「ホバー」セレクターは要素に一時的なスタイルを適用しますが、それは決定的なものではありません。
div:hover {
background-color: red;
}
javascriptでも同じことができますが、少し複雑で、いくつかの要素では不可能です。
var elem = document.getElementsByTagName ("div")[0];
elem.onmouseover = function () {
this.style.backgroundColor = "red";
}
elem.onmouseout = function () {
this.style.backgroundColor = "transparent";
}
もっと良い方法はありますか?このようなもの:
document.getElementsByTagName ("div")[0].ontemporarymouseover = function () { // LoL
this.style.backgroundColor = "red";
}
ありがとう