courses.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Lee Morgan -courses-</title>
  6. <link rel="stylesheet" href="/learn/style">
  7. </head>
  8. <body>
  9. <h1>Courses</h1>
  10. <div id="container" class="cardContainer"></div>
  11. <template id="template">
  12. <a class="card">
  13. <img>
  14. <div>
  15. <h2></h2>
  16. <p></p>
  17. </div>
  18. </a>
  19. </template>
  20. <script>
  21. fetch("/learn/courses")
  22. .then(response => response.json())
  23. .then((response)=>{
  24. let container = document.getElementById("container");
  25. let template = document.getElementById("template").content.children[0];
  26. for(let i = 0; i < response.length; i++){
  27. let course = template.cloneNode(true);
  28. course.href = `/learn/course/${response[i]._id}`;
  29. course.children[0].src = response[i].thumbNail;
  30. course.children[0].alt = `${response[i].title} thumbnail`;
  31. course.children[1].children[0].innerText = response[i].title;
  32. course.children[1].children[1].innerText = response[i].description;
  33. container.appendChild(course);
  34. }
  35. })
  36. .catch((err)=>{});
  37. </script>
  38. </body>
  39. </html>