Advertisement
perjespersson

Untitled

Jan 19th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. .box
  6. {
  7. width: 300px;
  8. margin-left: 10px;
  9. float: left;
  10. background-color:blue;
  11. color: white;
  12. }
  13. </style>
  14. <script>
  15. function addElement () {
  16.  
  17.  
  18. var cars = ["InneKravallen", "SunTrip", "Valla Pyjamas Rave"];
  19. var hosts = ["CM", "SM", "Valla Skivgarde"];
  20. var datum = ["23 Januari", "5 Maj", "27 Mars"];
  21. var plats = ["Kårallen", "Skytte C", "KK"];
  22.  
  23. for(var i = 0; i <cars.length; i++)
  24. {
  25. var box = document.createElement("div");
  26. box.setAttribute("class", "box");
  27.  
  28. //Rubrik
  29. var rubrik = document.createElement("H1");
  30. var rubriken = document.createTextNode(cars[i]);
  31. rubrik.appendChild(rubriken);
  32. box.appendChild(rubrik);
  33.  
  34. //Underrubik
  35. var underrubrik = document.createElement("H2");
  36. var underrubriken = document.createTextNode(hosts[i]);
  37. underrubrik.appendChild(underrubriken);
  38. box.appendChild(underrubrik);
  39.  
  40. //Datum
  41. var datum = document.createElement("P");
  42. var datumet = document.createTextNode(datum[i]);
  43. datum.appendChild(datumet);
  44. box.appendChild(datum);
  45.  
  46. //Plats
  47. var plats = document.createElement("P");
  48. var platsen = document.createTextNode(String(plats[i]));
  49. plats.appendChild(platsen);
  50. box.appendChild(plats);
  51.  
  52. //Printa till skärmen
  53. document.body.appendChild(box);
  54. }
  55. }
  56.  
  57.  
  58.  
  59. </script>
  60. <title>||Working with elements||</title>
  61. </head>
  62. <body onload="addElement()">
  63. <div id="div1">Boxarna genereras automatiskt</div>
  64. </body>
  65. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement