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

122
Views
why i can't add new todo item after refresh js

I have this problem: I add my card and to do list item to local storage and and after page refresh I can't click on it,

The problem is that: when I try to add after page refresh, it doesn't add new element on "todo task", before refresh, when I click on element I can open modal popup, but after refresh I can't.

Here is my code:

https://jsfiddle.net/adulik/ztjf0y1m/1/

function addTaskListItem(id) {
    //get element by id
    const task = document.getElementById(id);

    //creating new task in block
    let localItems = JSON.parse(localStorage.getItem("localItem"));
    const item = localItems.find(el => el.id === id);

    if (item.tasks) {
        item.tasks.push(task.value)
    } else {
        item.tasks = [task.value]
    }
    localItems = localItems.filter(el => el.id !== id);
    localItems.push(item);
    localStorage.setItem("localItem", JSON.stringify(localItems))

    if (task.value.length === 0) {
        alert('add new task');
        return []
    }

    const list = document.getElementById(`${id}-list`);
    const listItem = createElement('div', task.value, 'list-item');

    listItem.addEventListener("dblclick", togglecontainer);
    closeButton.addEventListener("click", togglecontainer);
    window.addEventListener("click", windowOnClick);

    listItem.setAttribute('draggable', true);
    task.value = '';
    list.append(listItem);
    dragNDrop();
}
about 4 years ago · Santiago Trujillo
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!