javascript - Function executes regardless of the localStorage if statement -


this question has answer here:

i'm trying execute javascript function depending on value of localstorage key. seems pretty easy, i'm not getting anywhere. here's have -

        <script>     window.onload = function ()     {         setinterval(function()         {             var 1 = localstorage.getitem('one');             if (one !== true)             {                 var elem = document.getelementbyid("one");                 elem.classname = "hide";             }              else if (one !== false)              {                 var elem = document.getelementbyid("one");                 elem.classname = "show";             }             else {                 var elem = document.getelementbyid("one");                 elem.classname = "show";             }         }, 50);     } </script> 

what supposed check every 50ms key "one" in localstorage. if it's true, execute function defined under if statement. if it's false, execute other function that's defined under else or else if statements.

unfortunately, doesn't matter whether or not there entry in localstorage @ all, executes first function(hiding object). i'm not sure why.

any suggestions appreciated.

thanks.

edit - couldn't find information in other posts, because issue has points brought in comments , answers. if string "true" isn't in localstorage begin with, why function still executing?

anything stored in localstore strictly store string key/value pairs. means storing string: "true" , not boolean value true.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -