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