File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ const inputBox = document . getElementById ( "input-box" ) ;
2+ const listContainer = document . getElementById ( "list-container" ) ;
3+
4+ function addTask ( ) {
5+ if ( inputBox . value === '' ) {
6+ alert ( "You must write some Task!" ) ;
7+ } else {
8+ let li = document . createElement ( "li" ) ;
9+ li . innerHTML = inputBox . value ;
10+ listContainer . appendChild ( li ) ;
11+
12+ let span = document . createElement ( "span" ) ;
13+ span . innerHTML = "\u00d7" ;
14+ span . classList . add ( "close" ) ;
15+ li . appendChild ( span ) ;
16+ }
17+ inputBox . value = "" ;
18+ saveData ( ) ;
19+ }
20+
21+ listContainer . addEventListener ( "click" , function ( e ) {
22+ if ( e . target . tagName === "LI" ) {
23+ e . target . classList . toggle ( "checked" ) ;
24+ saveData ( ) ;
25+ } else if ( e . target . tagName === "SPAN" ) {
26+ e . target . parentElement . remove ( ) ;
27+ saveData ( ) ;
28+ }
29+ } , false ) ;
30+
31+ function saveData ( ) {
32+ localStorage . setItem ( "tasks" , listContainer . innerHTML ) ;
33+ }
34+
35+ function loadTasks ( ) {
36+ listContainer . innerHTML = localStorage . getItem ( "tasks" ) ;
37+ }
38+
39+ loadTasks ( ) ;
You can’t perform that action at this time.
0 commit comments