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

180
Visualizações
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
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