File tree Expand file tree Collapse file tree
apps/localStorage-and-event-delegation Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- const form = document . querySelector ( '.form' ) ;
2- let list = document . querySelector ( '.list' ) ;
3- const input = document . querySelector ( '.form__input' ) ;
4- let items = [ ] ;
1+ const addItems = document . querySelector ( '.form' ) ;
2+ const itemsList = document . querySelector ( '.list' ) ;
53
6- const addItems = e => {
4+ const addItem = e => {
75 e . preventDefault ( ) ;
8- let input = document . querySelector ( '.form__input' ) ;
9- items = [ ... items , input . value ] ;
6+ const text = getInputValue ( ) ;
7+ const element = createElement ( text ) ;
108
11- createElement ( items ) ;
9+ itemsList . insertAdjacentHTML ( 'beforeend' , element ) ;
1210
13- input . value = '' ;
11+ e . target . reset ( ) ;
1412} ;
1513
16- const createElement = items =>
17- items . map (
18- ( value , index ) => `<li><label for="item${ index } ">${ value } </label></li>`
19- ) ;
14+ const getInputValue = ( ) => {
15+ const text = document . querySelector ( '.form__input' ) . value ;
16+ const item = {
17+ text,
18+ done : false
19+ } ;
20+ return item ;
21+ } ;
22+
23+ const createElement = item => `
24+ <li class="list__item">
25+ <input class="list__item__checkbox" name="item" type="checkbox" ${
26+ item . done ? 'checked' : ''
27+ } />
28+ <label for="item">${ item . text } </label>
29+ </li>
30+ ` ;
2031
21- addEventListener ( 'submit' , addItems ) ;
32+ addItems . addEventListener ( 'submit' , addItem ) ;
Original file line number Diff line number Diff line change 1111 rel ="stylesheet "
1212 href ="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css "
1313 />
14- < link rel ="stylesheet " href ="./assets/style/index.css " />
1514 < link
1615 href ="https://fonts.googleapis.com/css?family=Roboto+Condensed:300,400,700 "
1716 rel ="stylesheet "
1817 />
1918
19+ < link rel ="stylesheet " href ="./assets/style/index.css " />
2020 < link rel ="icon " href ="./assets/img/favicon.png " />
2121
2222 <!-- More tags -->
@@ -67,11 +67,11 @@ <h1 class="content__title">Fancy foods</h1>
6767
6868 < ul class ="list ">
6969 < li class ="list__item ">
70- < input class ="list__item__checkbox " type ="checkbox " />
70+ < input class ="list__item__checkbox " name =" item " type ="checkbox " />
7171 < label for ="item "> Beef Bourguignon</ label >
7272 </ li >
7373 < li class ="list__item ">
74- < input class ="list__item__checkbox " type ="checkbox " />
74+ < input class ="list__item__checkbox " name =" item " type ="checkbox " />
7575 < label for ="item "> Salad Nicoise</ label >
7676 </ li >
7777 </ ul >
You can’t perform that action at this time.
0 commit comments