Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
Using onclick attribute when using Vanilla JavaScript

I need to know why when I use onclick attribute in HTML file it works fine but when I change the script tag to be module id doesn't work and gives me this error main is not defined when I click the button

<!--index.html-->
  <body>
    <button onclick="main()">test</button>
    <script type="module" src="./index.js"></script>
  </body>
function main() {
  const newDev = document.createElement("p");
  newDev.textContent = "function works well";
  document.body.appendChild(newDev);
}

error I get when I click the button

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda