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

98
Visualizações
Deleting class from an element

I'm making a task board project. Must say I'm using only HTML, CSS, JS, and nothing else right now. I'm making a fade-in effect to the newly added note (ul element), and I would like to delete the fade-in class from the previously added note. this is a chunk of my code that displays the note inside the div.

function displayAllTasks(allTasks){
  taskNotesDiv.innerHTML = "";
  for(const task of allTasks){
    const index = allTasks.indexOf(task);
    const note = `
      <div class"noteDiv">
        <ul class="fadeInNote">
          <button type="button" onclick="deleteTask(${index})">
            <i class="fa-solid fa-trash deleteButton"></i>
          </button>
          <li>Task: ${task.task}</li>
          <li>Description: ${task.textArea}</li>
          <li>Date: ${task.date}</li>
          <li>Time: ${task.time}</li>
        </ul>
      </div>
    `
    taskNotesDiv.innerHTML += note;
  }   
}

I tried already another function to delete it but with no success.

any help would be appreciated!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There can be multiple approaches, but my approach is to create element using document.createElement . The modified JS will become:

function displayAllTasks(allTasks) {
    last_ul = null;  // store the last ul element added
    taskNotesDiv.innerHTML = "";
    for (const task of allTasks) {
        const index = allTasks.indexOf(task);

        let noteDiv = document.createElement('div');
        noteDiv.classList.add('noteDiv');
        
        note_ul = document.createElement('ul');
        note_ul.classList.add('fadeInNote');
        note_ul.innerHTML = `
            <button type="button" onclick="deleteTask(${index})">
                <i class="fa-solid fa-trash deleteButton"></i>
            </button>
            <li>Task: ${task.task}</li>
            <li>Description: ${task.textArea}</li>
            <li>Date: ${task.date}</li>
            <li>Time: ${task.time}</li>`

        noteDiv.appendChild(note_ul);
        // if it is not the first element, then remove the class from previous
        if (last_ul != null) {
            last_ul.classList.remove('fadeInNote');
        }
        last_ul = note_ul;  // this becomes previous for next iteration
        taskNotesDiv.appendChild(noteDiv);
    }
    // remove class of the last element
    if (last_ul != null) {
        last_ul.classList.remove('fadeInNote');
    }
    
}
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