Skip to content

Instantly share code, notes, and snippets.

@codebubb
Created September 23, 2019 14:18
Show Gist options
  • Select an option

  • Save codebubb/f2373bd02ca74a749bd23699ce5961f2 to your computer and use it in GitHub Desktop.

Select an option

Save codebubb/f2373bd02ca74a749bd23699ce5961f2 to your computer and use it in GitHub Desktop.
Hover with JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hover with JavaScript</title>
<style>
#hoverlink {
padding: 5px;
text-decoration: none;
background-color: rgb(199, 82, 82);
color: #fff;
box-shadow: 0px 0px 2px 2px rgba(0,0,0,0.1);
font-family:Arial, Helvetica, sans-serif;
}
</style>
</head>
<body>
<a id="hoverlink" href="#">Hover test</a>
<script>
hoverlink.addEventListener('mouseenter', (e) => {
console.log('Mouse enter');
});
hoverlink.addEventListener('mouseleave', (e) => {
console.log('Mouse leave');
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment