I have a simple boilerplate HTML template.
All I want to do is run a simple script which I have installed as an npm package – the script just appends the word “test” into a div with the id of “result”:
const test = () => {
$('#result').append('test')
}
Currently, the npm package installs fine and works fine by using this script tag:
<script src="../node_modules/@MYUSERNAME/testgenerator/id.js"></script>
However, this script ONLY runs if I call the function separately in a separate script tag:
<script>test()</script>
Is there a way to make the script run WITHOUT having to use this extra script tag with the function call?
I tried adding the call to the original script like so:
const test = () => {
$('#result').append('test')
}
test()
But this did nothing.
Is there any way I can get the script to run without having to call it in a separate script tag ?
Full code:
<!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>HTML 5 Boilerplate</title>
<link rel="stylesheet" href="style.css">
<script src="../node_modules/@MYUSERNAME/testgenerator/id.js"></script>
</head>
<body>
<div id="result"></div>
<script>test()</script>
</body>
</html>