I'm currently serving a /frontend.js file inside my public folder inside an express application. I have then added this to the head tag of my EJS file inside <script> tags. As seen below:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wow Leaderboards - 2v2 US</title>
<link rel="stylesheet" href="/css/medstyle.css">
<link rel="stylesheet" href="/css/home.css">
<script src="/frontend.js"></script>
</head>
<body>
I then add a button to my EJS file which im using to call an alert function inside the /frontend.js file.
Button inside .ejs file
<button onclick="myFunction()">Click me</button>
function inside frontend.js
function myfunction(){
alert('hello')
}
myfunction()
The function works inside the EJS file when the page loads if i call it inside of the frontend.js file but it does nothing when I try to call it using the onClick method. I have noidea why this is not working. Anyhelp is much appreciated. Thanks in advance.