javascript - Why is my localStorage code not working? -
i'm trying make div div disappear , stay gone when user comes back. doesn't seem want. when press button, nothing happens. not value of localstorage changes...
localstorage.done = localstorage.done || false; $('#mybutton').addeventlistener('click', function() { if (!localstorage.done) { localstorage.done = true; $('#mydiv').style.display = "none"; } });
you code localstorage
working (even if suggested use getter/setter methods instead of direct property access).
your problem this:
$('#mybutton').addeventlistener('click', function() {
jquery not know .addeventlistener
want call .bind()
localstorage.done = localstorage.done || false; $('#mybutton').bind('click', function() { if (!localstorage.done) { localstorage.done = true; $('#mydiv').hide(); } });
Comments
Post a Comment