Javascript Event How to - Create hover effect with mouse out and over action








Question

We would like to know how to create hover effect with mouse out and over action.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--  w  w w  .ja v a 2  s.c o  m-->
function show() {
    document.getElementById('cat').style.display = "block";
}
function hide() {
    document.getElementById('cat').style.display = "none";
}

</script>
</head>
<body>
  <a href='#' onmouseover='show();' onmouseout='hide();'>hover</a>
  <div id='cat' style='display: none;'>cat</div>
</body>
</html>

The code above is rendered as follows: