View difference between Paste ID: j5NQJGnv and FiC8DL41
SHOW: | | - or go back to the newest paste.
1
<!DOCTYPE html>
2
<html lang="pl">
3
  <head>
4
    <meta charset="utf-8" />
5
    <meta name="viewport" content="width=device-width, initial-scale=1" />
6
7
    <title>Hello World!</title>
8
    <link rel="stylesheet" href="/style.css" />
9
    <script src="/script.js" defer></script>
10
  </head>
11
12
  <body>
13
    <div id="addElement">
14
      <h1>Shopping List</h1>
15
16
      <input id="element" type="text" maxlength="25" />
17
      <button id="addButton">Add Product</button>
18
      <button id="printButton">Print</button>
19
20
      <p id="message"></p>
21
    </div>
22
    <div id="forPrinting">
23
      <div id="listContainer">
24
        <ol id="taskList"></ol>
25
      </div>
26
    </div>
27
  </body>
28
</html>
29
30
31
============================= JavaScript ==================================
32
33
// event when the user clicks on the add button
34
document.getElementById("addButton").addEventListener("click", function () {
35
  // to the variable we assign the text that the user typed in the input field
36
  const newElement = document.getElementById("element").value.trim();
37
  // if the text is different from empty i.e. the user has typed a string of characters
38
  if (newElement != "") {
39
    // we clear the possible message
40
    document.getElementById("message").textContent = "";
41
    // we add a new item to our numbered list
42
    document.getElementById("taskList").innerHTML +=
43
      "<li>" + newElement + "</li>";
44
    // clear the input field
45
    document.getElementById("element").value = "";
46
  } else {
47
    // we display a message because the user has not entered anything
48
    document.getElementById("message").textContent = "Fill the field";
49
  }
50
});
51
52
// event after clicking on the task list
53
document.getElementById("taskList").addEventListener("click", function (e) {
54
  //write the reference to the list element that was clicked to a variable
55
  const elementList = e.target;
56
  //remove the clicked list element
57
  this.removeChild(elementList);
58
});
59
60
document.getElementById("printButton").addEventListener("click", function () {
61
  const printArea = document.getElementById("forPrinting").innerHTML;
62
  //we set the print area only for the elements of our task list
63
  document.body.innerHTML = printArea;
64
  //print window
65
  window.print();
66
  //refresh the entire page
67
  window.location.reload();
68
});
69
70
================================== CSS ==================================
71
72
@import url("https://fonts.googleapis.com/css?family=Caveat+Brush&display=swap");
73
body {
74
  background-image: url("https://cdn.glitch.com/cd3369a7-e614-49a9-93c1-8871829b4d63%2Fandrew-neel-cckf4TsHAuw-unsplash.jpg?v=1584885423509");
75
  background-repeat: no-repeat;
76
  background-size: cover;
77
  background-attachment: fixed;
78
  font-family: "Caveat Brush", cursive;
79
}
80
#addElement {
81
  margin: 0px auto 0px auto;
82
  width: 1000px;
83
  text-align: center;
84
  padding: 10px;
85
}
86
87
li {
88
  margin-left: auto;
89
  margin-right: auto;
90
  width: 200px;
91
  height: 30px;
92
  border-radius: 10px;
93
  padding: 10px;
94
}
95
96
li:hover {
97
  color: red;
98
  cursor: pointer;
99
  text-decoration: line-through;
100
}
101
102
h1 {
103
  font-size: 5em;
104
  color: white;
105
}
106
107
#taskList {
108
  font-family: "Caveat Brush", cursive;
109
  font-size: 32px;
110
  width: 500px;
111
  background-color: #ffd35c;
112
  margin-left: auto;
113
  margin-right: auto;
114
  border-radius: 10px;
115
  color: #003a91;
116
}
117
#addButton,
118
#printButton {
119
  width: 200px;
120
  height: 50px;
121
  background-color: #fa4a0a;
122
  color: white;
123
  padding: 15px 32px;
124
  font-size: 16px;
125
  border-radius: 4px;
126
  transition-duration: 0.4s;
127
  border: 2px solid #fa4a0a;
128
  text-transform: uppercase;
129
}
130
131
#printButton:hover,
132
#addButton:hover {
133
  cursor: pointer;
134
  opacity: 0.8;
135
}
136
137
input {
138
  width: 330px;
139
  height: 30px;
140
  font-family: "Caveat Brush", cursive;
141
  font-size: 20px;
142
}
143
144
p {
145
  color: white;
146
  font-size: 180%;
147
}
148