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

79
Views
Add localStorage on to-do list JS

i was trying to add localStorage on my to-do list, but it just returns me 'undefined' and off the <'li'> that <'li'> is created when you input a value. I've already tried to use the id="myList" inside a <'li'> but it didn't worked

            <form>
                <input type="text" nome="task" id='task' placeholder="New..." />
                <input type="button" nome="" value='AddTask' onclick="addTask()" />
            </form>

                <ul id="myList">
                </ul>

<script type="text/javascript">
    var ul = document.getElementById("myList");

    addTask = function() {
        if (document.getElementById("task").value != ""){
            let item = document.getElementById("task");
            let itemId = Date.now().toString('16') + Math.random().toString('16').substring(2);
            ul.innerHTML += `<li id=${itemId}>${item.value}<button onclick="removeTask('${itemId}')">X</button></li>`
            
            saveLocalStorage()
        }
    }

    removeTask = function (itemId) {
        document.getElementById(itemId).remove()
        saveLocalStorage()
    }

    saveLocalStorage = function() {
        localStorage.setItem('savedList', ul.InnerHTML)
        
    }

    window.onload = function() {
        ul.innerHTML=localStorage.getItem('savedList')
    }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Check spelling:

localStorage.setItem('savedList', ul.InnerHTML)

it should be ul.innerHTML.

about 4 years ago · Juan Pablo Isaza Report

0

I did not understand what you exactly want, but try to add to to localstorage with JSON.stringify() like:

localStorage.setItem('savedList', JSON.stringify(ul.innerHTML));

and get it via JSON.parse() command:

const items = localStorage.getItem('savedList');
ul.innerHTML = JSON.parse(items);

Also carefull with spellings and like Inner and inner.

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!