Mouseover & Mouseout w/ Javascript

When you call an inline event handler such as you do with onmouseover="MouseOver(this);" you’re passing a reference to the element itself to your function, and in your function you’re taking that reference and assigning it to the variable elem.

You would then normally use elem within your function like elem.style.color = "white";, not with parenthesis, as you’re not running a function but rather just changing a property.

function MouseOver(elem) {
  elem.style.color = "white";
}

function MouseOut(elem) {
  elem.style.color = "black";
}
<nav id="frame-link">
  <a href="index.html" name="home" onmouseover="MouseOver(this);" onmouseout="MouseOut(this);">Home</a>
</nav>

Leave a Comment