File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 66    < title > Document</ title > 
77</ head > 
88< style > 
9+     * 
10+         margin :  0 ;
11+         padding :  0 ;
12+         box-sizing :  border-box;
13+     }
14+ 
915    body  {
16+         padding :  1rem  ;
1017        display :  grid;
1118        place-items :  center;
1219    }
20+ 
21+     .post  {
22+         margin :  1rem  ;
23+         padding :  1rem  ;
24+         border :  0.125rem   solid black;
25+     }
26+ 
27+     h1  {
28+         padding :  1rem  ;
29+     }
1330</ style > 
1431< body > 
1532    < button  id ="fetch-api-button "> Click To Fetch</ button > 
33+     < h1 > API Titles</ h1 > 
1634    < div  class ="append-titles "> 
17-         < h1 > API Titles</ h1 > 
1835    </ div > 
1936
2037
Original file line number Diff line number Diff line change @@ -20,19 +20,20 @@ async function fetchTodo(apiUrl) {
2020function  appendData ( data )  { 
2121    const  container  =  document . querySelector ( '.append-titles' ) ; 
2222    data . forEach ( ( item )  =>  { 
23-         const  newTitle  =  document . createElement ( 'span' ) ; 
23+         const  newTitle  =  document . createElement ( 'div' ) ; 
24+         newTitle . className  =  'post' ; 
2425        newTitle . innerHTML  =  item . title ; 
2526        container . appendChild ( newTitle ) ; 
2627    } ) ; 
2728} 
2829
2930// Helper function to store data from fetch function and pass on to appendData function 
30- const   getData   =   async  ( )   =>  { 
31+ async  function   clickHandler ( )  { 
3132    const  data  =  await  fetchTodo ( postApi ) ; 
3233    appendData ( data ) ; 
3334} 
3435
3536window . onload  =  ( )  =>  { 
3637    const  button  =  document . getElementById ( 'fetch-api-button' ) ; 
37-     button . addEventListener ( 'click' ,  getData ) ; 
38+     button . addEventListener ( 'click' ,  clickHandler ) ; 
3839} 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments