Animations
API
Arrays
Async
Basics
Challenges
Classes
Console
Dates
Debugging
DOM Elements
DOM Methods
DOM Properties
Event Listeners
Flow Control
Forms
Functions
Global Functions
JSON
Keywords
Libraries (3rd party)
Math
Modules
Objects
Snippets
String
Types
Widgets
Window Object
The mouseover
and mouseout
events can be used to trigger a function when the user mouses over, or out of, an HTML
element. These are events of any element within the document object.
// In HTML:
<element onmouseover="myScript"></element>
// In JavaScript:
object.onmouseover = function(){myScript};
// In JavaScript, using the addEventListener() method:
object.addEventListener("mouseover", myScript);
document.getElementById("demo").addEventListener("mouseover", function () { MakeRed(this); });
document.getElementById("demo").addEventListener("mouseout", function () { MakeNormal(this); });
function MakeRed(control)
{
control.innerHTML = "Mouse over";
control.style.color="#ff0000";
control.style.background = "#ffcc00";
}
function MakeNormal(control)
{
control.innerHTML = "Mouse out";
control.style.color = "#000000";
control.style.background = "#ffffff";
}