Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda