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

176
Views
How to save dynamically added checkboxes' styles after refreshing page?

To-do list. I have dynamic added checkboxes and styles for them in css. I wanna save checked checkboxes styles after refreshing the page using local storage. I've tried everything but nothing works. Any ideas? Thank you. (Also checkboxes are already in the local storage) Here's full code https://github.com/cyber8nav/To-do-list

function addTask(nameOfTheNewTask) {
let task = {
    id: Date.now(),
    name: nameOfTheNewTask,
    completed: false
};

tasks.push(task);
textArea.value = "";
addTaskWindow.style.display = "none";
tasksWindow.style.display = "block";
if (tasks.length == 1) {
    amount.textContent = tasks.length + " " + "Task";
} else {
    amount.textContent = tasks.length + " " + "Tasks";
}
renderTask(tasks);
addToStorage(tasks);}
function renderTask(tasks) {
list.innerHTML = "";
tasks.forEach((item) => {
    const newTask = document.createElement("li");
    newTask.setAttribute("data-key", item.id);
    newTask.innerHTML = `
    <label class = "tasks__item">
        <input type = "checkbox" class = "checkbox" name = "task">
        <span>${item.name}</span>
    </label>
    <img class="delete" src="img/icons/delete.svg" alt="del" width="18px" height="20px">`;
    list.append(newTask);
});}
 // checkbox    
    &::before{
        content: '';
        display: inline-block;
        width: 1.2em;
        height: 1.2em;
        border-radius: 50%;
        border: 2px solid $darkgrey;
        position: absolute;
        left: 0;
        top: 0;
    }
}
// checked checkbox
input[type=checkbox] + span::after{
    content: '';
    opacity: 0;
    transition: opacity 0.6s ease;
}

input[type=checkbox]:checked + span::after{
    content: '✓';
    color: $blue;
    font-weight: 900;
    position: absolute;
    left: 0.225rem;
    top: -0.025rem;
    opacity: 1;
}
input[type=checkbox]:checked + span{
    color: $grey;
    text-decoration: line-through;
    animation: strike 1s linear;
    transition: color 0.6s ease-out;
}
input[type=checkbox]:checked + span::before {
    border: 2px solid $blue;
    transition: color 1s ease-out;
}

}

about 4 years ago · Juan Pablo Isaza
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!