I have been learning how to design a custom Wordpress theme using php, html, css and javascript. I am using the Wordpress development tool Local to view my website when I make a change. I am a beginner to all of these languages and I am having an issue with executing my javascript function when a button is clicked in the navigation. The button is supposed to display a slideout menu after it is clicked. I am not sure if this is an issue with my html and javascript syntax or if I am linking them incorrectly(either in the html file or the functions.php file). Anyways, this is what I have so far that may be causing the issue.
header.php
<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">
<?php wp_head(); ?>
<script src="js/main.js"></script>
</head>
<body>
<div id ="slideout-menu">
<ul>
<li>
list items
</li>
</ul>
</div>
<nav>
<ul>
<li><a href ="#">Home</a></li>
<li><a href ="#">About</a></li>
<li><button onclick="showSlideOutMenu();">Projects</button></li>
</ul>
</nav>
main.js
const slideoutMenu = document.getElementById("slideout-menu");
function showSlideOutMenu(){
if(slideoutMenu.style.opacity == "1"){
slideoutMenu.style.opacity = '0';
slideoutMenu.style.pointerEvents = 'none';
}
else{
slideoutMenu.style.opacity = '1';
slideoutMenu.style.pointerEvents = 'auto';
}
}
functions.php
<?php
function js_css_setup(){
wp_enqueue_style('style', get_stylesheet_uri(), '/css/style.css');
wp_enqueue_script("main", get_theme_file_uri() .'/js/main.js', NULL,microtime(),false);
}
add_action('wp_enqueue_scripts','js_css_setup');
?>
The style.css is functional and displays the menu when the opacity is set to 1 so I ruled that out. My webpage can also display an alert message if added to the main.js. Does anything else that may be causing the issue stick out?