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

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

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