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

127
Views
JS: Pass items from arrays as parameters for a function

for example:

function example({array 1 item x}, {array 2 item x})

I'd imagine I'll need some sort of for loop that passes each item individually with the equivalent item from both arrays.

actual code:

function hide(bool, item) {
  if (bool) {
    document.getElementById(item).classList.add("hide");
    document.getElementById(item).classList.remove("show");
    bool = false;
  }
}

I need to run this for every id I want to hide and show, so I figured I could put the bools list and items list in an array and individually run them together to eliminate unnecessary redundancy.

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

0

If you want to hide and show element using one function call

this will hide or show multiple element by id

function showAndHide(bool, item) {
  if (bool.length !== item.length) throw new Error('bool and item length is different')

  bool.forEach((bool2, index) => {
    if (bool2) {
      document.getElementById(item[index]).classList.add("show");
      document.getElementById(item[index]).classList.remove("hide");
    } else {
      document.getElementById(item[index]).classList.add("hide");
      document.getElementById(item[index]).classList.remove("show");
    }
  })
}
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!