<div>
<p>EventListener</p>
<h2 id="mouseEventOne">Mouse over 1</h2>
</div>
<div>
<p>HTML onChange function</p>
<h2 id="mouseEventTwo" onmouseover="mouseOver()" onmouseout="mouseOut()">Mouse over 2</h2>
</div>
<div>
<p>JS onChange function</p>
<h2 id="mouseEventThree">Mouse over 3</h2>
</div>
<script>
const mouseEventOne = document.getElementById('mouseEventOne');
// Using addEventListener
mouseEventOne.addEventListener('mouseover', () => {
document.getElementById("mouseEventOne").style.color = "red";
});
mouseEventOne.addEventListener('mouseout', () => {
document.getElementById("mouseEventOne").style.color = "black";
});
const mouseOver = () =>{
document.getElementById("mouseEventTwo").style.color = "blue";
}
const mouseOut = () =>{
document.getElementById("mouseEventTwo").style.color = "black";
}
const mouseEventThree = document.getElementById('mouseEventThree');
mouseEventThree.onmouseover = function() {
document.getElementById("mouseEventThree").style.color = "green";
};
mouseEventThree.onmouseout = function() {
document.getElementById("mouseEventThree").style.color = "black";
};
</script>