fixed friendly button

This commit is contained in:
ari melody 2024-04-07 00:29:51 +01:00
parent f7f6254016
commit 1fcb473c5f
Signed by: ari
GPG key ID: CF99829C92678188

View file

@ -40,17 +40,22 @@
</p> </p>
<button id="friendly-button">friendly button</button> <button id="friendly-button">friendly button</button>
<script> <script>
const button = document.getElementById("friendly-button"); function hook_button() {
let clicks = 0; const button = document.getElementById("friendly-button");
let saved_clicks = window.localStorage.getItem("friendly-button-clicks"); if (!button) return;
if (saved_clicks) { let clicks = 0;
clicks = saved_clicks; let saved_clicks = window.localStorage.getItem("friendly-button-clicks");
button.innerText = `clicked ${clicks} times!`; if (saved_clicks) {
clicks = saved_clicks;
button.innerText = `clicked ${clicks} times!`;
}
button.addEventListener("click", () => {
button.innerText = `clicked ${++clicks} times!`;
window.localStorage.setItem("friendly-button-clicks", clicks);
});
} }
button.addEventListener("click", () => { document.addEventListener("ready", hook_button);
button.innerText = `clicked ${++clicks} times!`; document.addEventListener("htmx:load", hook_button);
window.localStorage.setItem("friendly-button-clicks", clicks);
});
</script> </script>
</main> </main>
<footer> <footer>