diff options
Diffstat (limited to 'quotes/public/script.js')
-rw-r--r-- | quotes/public/script.js | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/quotes/public/script.js b/quotes/public/script.js index 20587fe..8132019 100644 --- a/quotes/public/script.js +++ b/quotes/public/script.js @@ -21,10 +21,11 @@ function appendQuote(response) { "beforeend", `<li>${elem["name"]} ${elem["middlename"] ? elem["middlename"] : " "}${elem["surname"]}: ${ elem["quote"] - } <span data-id="${elem["id"]}">[Löschen]</span></li>`, + }${elem["owner"] ? '<span data-id="' + elem["id"] + '">[Löschen]</span></li>' : ""}`, ); - document.querySelector(`li span[data-id="${elem["id"]}"]`).addEventListener("click", (event) => { + const span = document.querySelector(`li span[data-id="${elem["id"]}"]`); + if (span) span.addEventListener("click", (event) => { fetch("api/delete/" + event.target.getAttribute("data-id"), { method: "DELETE" }) .then((response) => response.text()) .then((response) => { |