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 trial
brendon hanson
6,191 PointsHow to use localStorage with tables?
I need to be able to save the new tables that are added via jQuery. Also I gave the tables a content editable attribute so I need a way to save those changes as well. If anyone can help with this that would be amazing! I tried using localStorage but I couldn't get anywhere(I'm not very familiar with localStorage) If you need more code or have any questions please ask and I will answer quickly! Thanks
$(document).ready(function() {
// WHen button is clicked you fill out prompts and then a new row with new info appears
$('.addItem').click(function() {
while (true) {
let partNum = prompt("What is the part number?");
let quantity = prompt("What is the quantity of this part?");
let description = prompt("Describe this part(optional)");
$("table").find('tbody').append( `<tr><td contenteditable='true'>${partNum}</td><td contenteditable='true'>${quantity}</td><td contenteditable='true'>${description}</td></tr>` );
break;
}
});
});
1 Answer
Steven Parker
243,656 PointsIt sounds like you might benefit from the Using Local Storage with JavaScript workshop.
Also, you'll probably need some mechanism to detect when edits are made. Even with the "contenteditable" property set, "td" elements don't generate "change" or "input" events.