Here's what my code looks like on codepen (ignore broken image):
https://codepen.io/kornstalk/pen/ZEqXrgq
My issue is that whenever the code is run on browser, the animation on the icon breaks - the menu functions just fine (ignore the styling, I'm tweaking it later). This is my first time trying to use JS with HTMl & CSS, and it seems like the error's I've gotten are that Icon is undefined
Here is my full HTML Code:
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<title>Rlayout</title>
<meta name="description" content="This site will serve as the hub for many sub responsive
layouts">
<meta name="viewport" content="width=device-width, initial- scale=1">
<meta property="og:title" content="">
<meta property="og:type" content="">
<meta property="og:url" content="">
<meta property="og:image" content="">
<link rel="manifest" href="site.webmanifest">
<link rel="apple-touch-icon" href="icon.png">
<!-- Place favicon.ico in the root directory -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<meta name="theme-color" content="#fafafa">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<!-- Fonts-->
<!--Providence Sans-->
<link rel="stylesheet" href="https://use.typekit.net/xzx3vba.css">
</head>
<body>
<!-- Place your site's HTML here -->
<header class="header">
<img class="logo" src="img/giz2.jpg" alt="This is our company logo">
<nav class="main-nav">
<a href="">About</a>
<span> | </span>
<a href="">Contact</a>
<span> | </span>
<a href="">Work</a>
</nav>
<div class="mobile-nav-wrapper">
<a href="javascript:void(0);" class="icon" data= "hamburger-menu" onclick="myFunction()">
<span></span>
<span></span>
<span></span>
</a>
<nav id="myLinks" class="mobile-main-nav">
<a href="">Work <span></span></a>
<a href="">About</a>
<a href="">Contact</a>
</nav>
</div>
</header>
<footer>
<p>© 2500</p>
<div>
<img src="./img/giz2.jpg" alt="">
<img src="./img/giz2.jpg" alt="">
</div>
</footer>
<script src="js/main.js"></script>
</body>
</html>
I've tried using the code below, which results in no errors, but won't animate:
var Icon = document.querySelector(".icon");
var Icon1 = document.querySelector(".icon span:nth-child(1)");
var Icon2 = document.querySelector(".icon span:nth-child(2)");
var Icon3 = document.querySelector(".icon span:nth-child(3)");
any help would be super appreciated !!!