Advertisement
Mwafrika_Josue

Unable to select classes in generated html codes

Jan 26th, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Javascript codes
  2.  
  3. const handleGetJson = () => {
  4.   const work = document.getElementById('works');
  5.  
  6.   fetch(`data.json`, {
  7.     headers: {
  8.       'Content-Type': 'application/json',
  9.       Accept: 'application/json',
  10.     },
  11.   })
  12.     .then((response) => response.json())
  13.     .then((messages) => {
  14.       const data = Object.values(messages);
  15.  
  16.       let container = '';
  17.  
  18.       data.forEach((item) => {
  19.         const {
  20.           title,
  21.           description,
  22.           technologies,
  23.           image,
  24.           link,
  25.           linkText,
  26.           link2,
  27.           linkText2,
  28.           id,
  29.         } = item;
  30.  
  31.         const techno = Object.values(technologies);
  32.         container =
  33.           container +
  34.           `
  35.           <div class="card-${id}">
  36.         <div class="card-1-2">
  37.         <div class="image-container${id}"></div>
  38.       </div>
  39.       <div class="card-1-1">
  40.         <h2 class="titre">${title}</h2>
  41.         <ul>
  42.           <li class="cano">CANOPY</li>
  43.           <li class="dot empty"></li>
  44.           <li class="dot">Back End Dev</li>
  45.           <li class="dot empty"></li>
  46.           <li class="dot">2015</li>
  47.         </ul>
  48.         <p class="desc">
  49.           ${description}
  50.         </p>
  51.         <ul class="skills">
  52.           <li>${techno[0]}</li>
  53.           <li>${techno[1]}</li>
  54.           <li>${techno[2]}</li>
  55.           <li>${techno[3]}</li>
  56.         </ul>
  57.         <button type="button" class="btn-tonic">See project</button>
  58.       </div>
  59.       </div>
  60.         `;
  61.         work.innerHTML = container;
  62.       });
  63.     });
  64. };
  65. handleGetJson();
  66.  
  67. // pop up modal
  68.  
  69. const close = document.getElementsByClassName('close-modal')[0];
  70. const modal = document.getElementById('popup');
  71. const btn = document.querySelectorAll('.btn-tonic'); // unable to get all the buttons in the dynamically generated cards get all buttons
  72.  
  73. console.log(btn); // empty Nodelist
  74.  
  75.  
  76.  
  77.  
  78. // HTML CODES
  79.  
  80. <section id="works" class="works"></section>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement