Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>val()</code> is apparently meant for getting the <a href="http://api.jquery.com/val/" rel="nofollow">values of form elements</a>. Trying it on a list returns an empty string. You could just get the innerhtml using <code>$('#ul').html()</code>, then stringifying that for <code>localStorage</code>.</p> <p>Something like:</p> <pre><code>var l = $('#ul').html(); localStorage.comments = JSON.stringify(l); </code></pre> <p>To restore these at some later point (I use jQuery here since that's available anyway):</p> <pre><code>$('#ul').html(JSON.parse(localStorage.comments)); </code></pre> <p>(Untested). Any particular reason for taking this approach?</p> <p>Edit: it's easy enough to check what is actually being saved. In Chrome, the devtools are in the Chrome menu under <code>Tools</code>, or right-click anywhere in a webpage and <code>Inspect element</code>.</p> <p>LocalStorage (and a bunch of other stuff) is listed in the <code>Resources</code> tab. You can also go to the <code>Console</code> tab and type <code>localStorage</code> to access the object directly.</p> <p>Keep in mind localStorage only stores strings and is limited to 5MB per 'origin', which I take to mean host. If you do lots of testing on localhost, I imagine there's a chance you'll hit the quota at some point.</p> <p>Also, the previous commenter has a good point about using <code>getItem()</code>/<code>setItem()</code>. Instead of using <code>localStorage.comments</code> you'd use <code>localStorage.getItem('comments')</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload