Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!