I have the following:
$(document).ready(function () {
var store = window.localStorage;
$('#accounts > li > a').click(function (e) {
var store = window.localStorage;
e.preventDefault();
store.setItem('account1', $(this).html());
alert($(this).html());
alert(store.getItem('account1'));
});
...
When I make a change to the link the first alert gives me the correct value but the last alert just gives me null. I’m using Firefox 11 (very latest) and IE 9. I thought both would allow local storage.
Can anyone see what I am doing wrong. It seems very simple code. I just cannot get items to store.
Here’s the HTML I am using:
<div style="margin-top: 20px;" class="btn-group">
<label style="background: none; background-color: #333; width: 120px;"
class="btn btn-inverse" id="account">X</label>
<button data-toggle="dropdown" class="btn btn-inverse dropdown-toggle">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" id="accounts">
<li><a data-value="00" href="#">A</a></li>
<li><a data-value="01" href="#">B</a></li>
<li><a data-value="02" href="#">C</a></li>
<li><a data-value="16" href="#">D</a></li>
</ul>
</div>
I copied your code exactly as you have it above and put it on jsfiddle. I had to improvise the HTML, since you didn’t post it, but it works for me on Chrome, Safari and IE9.
I would suggest posting your HTML. That may be the problem.
Does this demo work for you?:
http://jsfiddle.net/ThinkingStiff/MRLEW/