javascript - local storage not giving correct results -


i trying build post notes. reading head first series. did code. somehow it's no working.

<form action="post">     <input id="note_text" type="text" placeholder="enter note">     <input type="button" id="add_button" value="add note">  </form> <ul id="postitnoteslist">      <li>this first note.</li>      <li>this second note.</li>  </ul> 

and here js

window.onload=init;  // add sticky page  function addstickytopage(value) {     var sticky = document.createelement("li");     span.setattribute("class", "sticky");     document.getelementbyid("postitnoteslist").appendchild(sticky); }    // create , sticky note localstorage function createsticky() {     var value = document.getelementbyid("note_text").value;     var key = "sticky_" + localstorage.length;     localstorage.setitem(key, value);     addstickytopage(value); }    function init() {      var button = document.getelementbyid("add_button");     button.onclick = createsticky;        (var = 0; < localstorage.length; i++) {         var key = localstorage.key(i);         if (key.substring(0, 6) == "sticky") {             var value = localstorage.getitem(key);             addstickytopage(value);         }     }   } 

so i've buld fiddle can check out here fiddle please tell me doing wrong. thanks.

i have updated fiddle. note : first should create dom element , append text element , append node body code should this:

window.onload=init();      function addstickytopage(value) {         var sticky = document.createelement("li");         sticky.setattribute("class", "sticky");         var t = document.createtextnode(value);         console.log(t);         sticky.appendchild(t);         document.getelementbyid("postitnoteslist").appendchild(sticky);     } 

and windows.onload = init()with brackets

thanks


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -