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

165
Views
use a function to not rewrite all ids

I am still the begininer in javascript.. I guess it can be written simpler, without retyping those IDs. Html file has got matching ids to clear after the form is resulted.

function deleteValues() {
    document.getElementById('firstFemale').value = "";
    document.getElementById('secondFemale').value = "";
    document.getElementById('thirdFemale').value = "";
    document.getElementById('mistakeFemale').innerHTML = "";
    document.getElementById('resultFemale').innerHTML = "";
    document.getElementById('firstMale').value = "";
    document.getElementById('secondMale').value = "";
    document.getElementById('thirdMale').value = "";
    document.getElementById('mistakeMale').innerHTML = "";
    document.getElementById('resultMale').innerHTML = "";
}

but what if I had a lot of different IDs? I know getElementbyId can only retract one element. Any help is appreciated.

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

0

You can take multiple approaches, but I'd probably add a class to the elements so you get could get a list of them. For instance, you might give them the class to-clear (class="to-clear") and then:

document.querySelectorAll(".to-clear").forEach(element => {
    if ("value" in element) {
        element.value = "";
    } else {
        element.innerHTML = "";
    }
});

More: querySelectorAll

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!