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

130
Visualizações
Similar blocks of code found in 2 location in IF ELSE statement. Consider refactoring JS
if (notesValue) {
  document.querySelector(`.card-${domain.id} .add-notes-button`).classList.add('notes-filled');
} else {
  document.querySelector(`.card-${domain.id} .add-notes-button`).classList.remove('notes-filled');
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

The refactoring is simply done by using the second force param of the toggle Method:

Element.classList.toggle("className", forceBoolean)
MDN Docs DOMTokenList.toggle()

const EL_button = document.querySelector(`.card-${domain.id} .add-notes-button`);
EL_button.classList.toggle('notes-filled', notesValue);
about 4 years ago · Juan Pablo Isaza Relatório

0

document
 .querySelector(`.card-${domain.id} .add-notes-button`)
 .classList
 .toggle('notes-filled', notesValue);
about 4 years ago · Juan Pablo Isaza Relatório

0

Using toggle is a good idea but for a more general case where a method like that doesn't exist you could choose which method on the object to target e.g.:

document.querySelector(`.card-${domain.id} .add-notes-button`)
  .classList[notesValue ? 'add' : 'remove']('notes-filled');
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