SHOW:
|
|
- or go back to the newest paste.
| 1 | // event when the user clicks on the add button | |
| 2 | document.getElementById("addButton").addEventListener("click", function () {
| |
| 3 | // to the variable we assign the text that the user typed in the input field | |
| 4 | const newElement = document.getElementById("element").value.trim();
| |
| 5 | // if the text is different from empty i.e. the user has typed a string of characters | |
| 6 | if (newElement != "") {
| |
| 7 | // we clear the possible message | |
| 8 | document.getElementById("message").textContent = "";
| |
| 9 | // we add a new item to our numbered list | |
| 10 | document.getElementById("taskList").innerHTML +=
| |
| 11 | "<li>" + newElement + "</li>"; | |
| 12 | // clear the input field | |
| 13 | document.getElementById("element").value = "";
| |
| 14 | } else {
| |
| 15 | // we display a message because the user has not entered anything | |
| 16 | document.getElementById("message").textContent = "Fill the field";
| |
| 17 | } | |
| 18 | }); | |
| 19 | ||
| 20 | ||
| 21 | // event after clicking on the task list | |
| 22 | document.getElementById("taskList").addEventListener("click", function (e) {
| |
| 23 | //remove the clicked list element | |
| 24 | this.removeChild(e.target); | |
| 25 | }); | |
| 26 | ||
| 27 | document.getElementById("printButton").addEventListener("click", function () {
| |
| 28 | const printArea = document.getElementById("forPrinting").innerHTML;
| |
| 29 | //we set the print area only for the elements of our task list | |
| 30 | document.body.innerHTML = printArea; | |
| 31 | //print window | |
| 32 | window.print(); | |
| 33 | //refresh the entire page | |
| 34 | window.location.reload(); | |
| 35 | }); | |
| 36 |