courses.html 1.5 KB

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