Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAhmed A
Full Stack JavaScript Techdegree Student 3,832 Points[solved] localStorage.setItem not working on the js file, but working when typed into the console.
I'm attempting the challenge at the end of the last video of this course, and I have added the following lines of code at the end of my js file. However, when I refresh the page to test it, it turns out that the local storage hasn't been updated. It works as intended only when I type the localStorage.setItem method on the console and refresh the page.
let saved = localStorage.getItem('invitedList');
if (saved) {
ul.innerHTML = saved;
}
localStorage.setItem('invitedList',ul.innerHTML);
1 Answer
Steven Parker
231,248 PointsThis might be an issue of when the data is saved. The script will save it immediately when the page loads, but if some dynamic process is adding content later, a manual save would get it where the script wouldn't.
if that's not it, or you need more help fixing it, make a snapshot of your workspace and post the link to it here.
Ahmed A
Full Stack JavaScript Techdegree Student 3,832 PointsAhmed A
Full Stack JavaScript Techdegree Student 3,832 PointsThanks for your suggestion. I actually solved this issue right after posting this question, turns out there was an error at the submit event listener which prevented program from executing the local storage setItem method.
Ahmed A
Full Stack JavaScript Techdegree Student 3,832 PointsAhmed A
Full Stack JavaScript Techdegree Student 3,832 PointsWhat if there is no best answer? In this case I solved it on my own.
Steven Parker
231,248 PointsSteven Parker
231,248 PointsI suppose you could post your solution as an answer and mark it "best answer".