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

129
Views
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 answers
Answer question

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 Report

0

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

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 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!