I have encountered a problem numerous times where I cannot get an onclick function in an external js file to work in my Laravel projects. Here is an example from my page source:
<button onclick="testMe()">test</button>
<script type="text/javascript" src="http://[myurl]/js/jobs.js"></script>
Inside jobs.js:
function testMe() {
console.log('i have appeared');
}
This example is from having my script tag be called AFTER I call on click. I have also tried adding the script BEFORE I call on click. I have also tried adding it to my <head>
, but the following error still persists:
Uncaught ReferenceError: testMe is not defined at HTMLButtonElement.onclick
I understand that it cannot find the function, but what else can I try to problem solve this? Is it possible to call onclick to an external JS file?
Edit:
Here is the relevant line of my webpack file:
.js('resources/js/jobs/jobs.js', 'public/js/jobs.js')
How I actually call it (opposed to how it looks viewing the page src):
<script type="text/javascript" src="{{ asset('js/jobs.js') }}"></script>
This is also definitely being brought in because I have a console log above the function, which is being logged to the console.