Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

99
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda