Ready to watch this entire course?
Become a member and get unlimited access to the entire skills library of over 4,900 courses, including more Web and personalized recommendations.Start Your Free Trial Now
- View Offline
- Including range form elements
- Modifying the display interactively
- Dragging items to wish lists
- Storing wish list items locally
- Saving and retrieving list items
Skill Level Intermediate
So there is a call to loadFaves, and now let's put in that code itself. I'll make a little extra room there, so we can see what's happening. So it's function loadFaves curly brace pair. Now the first thing we want to make sure is that the function that we're trying to load exists. So we'll use an if statement, if (localStorage.get item) and then another curly brace and then another set of parentheses and quotes, and we want to check to see if the items favorites is the one that exists.
So if that exists--and let's put in another curly brace pair here--then what we want to do is get it and then assign what we get to the inner HTML of the unordered list, which we know as the variable the faves. So, it's theFaves.innerHTML = localStorage.getItem, and in parentheses, favorites, semicolon at the end and save, and that's it.
Let's check our work in the browser. I'll refresh the page. Now, let's scroll down, and let's say this time we want the eye, the $400, one of our favorites. It shows up in our list. And let's bring in rabbit as well. Okay, so I'm going to just copy this URL, and open up a new tab, paste it in, and hit Refresh, and then when I scroll down, there are my favorites. Well, congrats! Your ecommerce catalog is now greatly enhanced and totally engaging, with three interwoven HTML5-related technologies.
I'm sure your users will appreciate the upgrade to their experience.