The onmouseenter event occurs when the mouse is moved onto an element.
It is often used with the onmouseleave event, which occurs when the mouse is moved out of an element.
function mouseEnter() {
document.getElementById("dpdemo")
}
function mouseLeave() {
document.getElementById("dpdemo")
}
As you can see there, we have first identified our functions in JavaScript. The element we are isolating and using this function is called "dpdemo", which is the name of the h3 ID.
< h3 id="dpdemo"
onmouseenter="mouseEnter()"
onmouseleave="mouseLeave()">Put mouse here! < / h3 >
3. Add cool color to make text change when mouse hovers over
function mouseEnter() {
document.getElementById("dpdemo").style.color = "#ff8566";
}
function mouseLeave() {
document.getElementById("dpdemo").style.color = "black";
}
As you can tell, all that is added at the end is the addition of a style.color element.