File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -2,16 +2,17 @@ var form = document.getElementById('todo-form');
22var toDoList = document . getElementById ( 'todo-items' ) ;
33var newToDo = document . getElementById ( 'todo-add-new' ) ;
44
5- var toDoArray = [ ] ;
6-
75var addToDo = function ( ) {
86 var txt = newToDo . value ;
9- toDoArray . push ( txt ) ;
10-
11- var items = '<li class="todo__item">' + toDoArray . join ( '</li><li class= "todo__item">' ) + '</li>' ;
12- toDoList . innerHTML = items ;
7+ var item = document . createElement ( "li" ) ;
8+ item . innerHTML = txt ;
9+ item . classList . add ( "todo__item" ) ;
10+ toDoList . appendChild ( item ) ;
1311 newToDo . value = '' ;
1412
13+ var contents = toDoList . innerHTML ;
14+ localStorage . setItem ( 'contents' , contents ) ;
15+
1516 var toDos = document . querySelectorAll ( 'li.todo__item' ) ;
1617
1718 var completeToDo = function ( ) {
@@ -21,6 +22,8 @@ var addToDo = function() {
2122 for ( var i = 0 ; i < toDos . length ; i ++ ) {
2223 toDos [ i ] . addEventListener ( 'click' , completeToDo , false ) ;
2324 }
25+
26+ return false ;
2427} ;
2528
2629
@@ -50,3 +53,7 @@ newToDo.onkeydown = function(event) {
5053 return false ;
5154 }
5255} ;
56+
57+ if ( localStorage . getItem ( 'contents' ) ) {
58+ toDoList . innerHTML = localStorage . getItem ( 'contents' ) ;
59+ }
You can’t perform that action at this time.
0 commit comments