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

254
Views
What will this code look like in Javascript?

I have problems, I wrote code in Jquery, the worker asks not to use it. This function should check the inputs for fullness

$('document').ready(function() {
    $('#btn').on('click', function() {
      $('.registration__labels .rfield').each(function() {
        if ($(this).val() == '') {
            console.log(2);
            $('input[required]').addClass('error');
        } else {
            console.log(1);
            $('input[required]').removeClass('error');
        }
      });
    });
});

here is the Jquery code, it works

document.addEventListener('DOMContentLoaded',function validation (){
  if(btn.addEventListener("click", function() {
    ('.registration__labels .rfield').forEach(() => {
        if (document.getElementsByClassName('input[type=text]').value == '') {
          console.log(2);
          (".input[required]").classList.add('error');
        }
        else {
          console.log(1);
          (".input[required]").classList.remove('error');
        }
      }
  )}))[validation]});

and this is me trying to translate it into javascript and it doesn't work. Help me pls

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

a way to do that...

window.addEventListener('DOMContentLoaded', () => 
  {
  const allRegLabs = document.querySelectorAll('.registration__labels .rfield')  

  document.querySelector('#btn').onclick = () =>
    {
    allRegLabs.forEach( el =>
      {
      let err =  el.classList.toggle('error', (el.value === ''))
      console.log( (err ? '2':'1' ))
      })
    }
  })
about 4 years ago · Juan Pablo Isaza 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!