HTML:
<body> <script type="module" src="./script.js"></script> <div>Welcome to my first html page...</div> <div id="username">Another div tag</div> <p>This is a paragraph</p> <h1>Working on JS</h1> <button onclick="firstFunction()">Click</button> </body>J/S:
function firstFunction() { console.log("Hurry") }Obtener error:
Uncaught ReferenceError: firstFunction is not defined at HTMLButtonElement.onclick (index.html:17) onclick @ index.html:17¿Cuál podría ser la causa de este error?
No importe el script js como módulo. use el siguiente código en su lugar:
<script src="./script.js"></script> `