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

172
Views
Code works perfectly on codepen but not in webstorm

The code that am trying in codepen worked, the same one does not work in webstorm. Nothing seem to work no error showing when clicking on button,

Example

const email = document.querySelector('.user-input');
const submit = document.querySelector('.btn0');
const error = document.querySelector('.mail-error');

const showError = () => {
error.style.display = 'block';
};

if (submit) {
  submit.addEventListener('click', (e) => {
    e.preventDefault();
    if (!email.value.match(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/)) {
       return showError();
    }
    document.getElementById("main0").style.display = "none";
    document.getElementById("main1").style.display = "block";
  });
}
<div id="main0">
  <input class="user-input" id="input-id" placeholder="Email" onblur="">
  <p class="mail-error" style="display: none;">Please enter valid email</p>
  <div class="btn0" id="btn0id" onclick="">NEXT</div>
</div>
<div id="main1" style="display:none;">
  <p> You now have access. <p>
</div>

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

document.addEventListener("DOMContentLoaded", function(event) {
    // put your code here
});
about 4 years ago · Santiago Gelvez Report

0

Fixed by adding "defer" when linking to the external script file, now everything works fine.

<script src="script.js" defer></script>
about 4 years ago · Santiago Gelvez Report
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!