HTML JS

ALLOW ONLY ONE CLICK IN JAVASCRIPT

DUSABLE BUTTON ON CLICK function demo () {    document.getElementById("btn")   .disabled = true;    alert("Something is done!");  }

DISABLE BUTTON

01

HTML BUTTON <input type="button" id="btn" onclick="demo()" value="Click"/>

ONLY RUN IF NOT CLICKED var clicked = false; function demo () { if (!clicked) {   clicked = true;   alert("Something is done!"); }}

PROTECTION FLAG

02

HTML BUTTON <input type="button" id="btn" onclick="demo()" value="Click"/>

HTML BUTTON <input type="button" id="btn" onclick="demo()" value="Click"/>

REMOVE ONCLICK

03

REMOVE ONCLICK WHEN CLICKED var clicked = false; function demo () {   document.getElementById("btn")   .onclick = "";    alert("Something is done!"); }

ATTACH CLICK LISTENER document.getElementById("btn") .addEventListener("click", demo);

EVENT LISTENER

04

DETACH CLICK LISTENER ON CLICK function demo () {   document.getElementById("btn")   .removeEventListener("click", demo);   alert("Something is done!"); }

HTML BUTTON <input type="button" id="btn" value="Click"/>

FUNKY VAR FUNCTION var switcher = demoA;

FUNCTIONS TO RUN function demoA () { alert ("Clicked"); } function demoB () {   alert("Something is done!");  clicker = demoB; }

HTML BUTTON <input type="button" id="btn" onclick="switcher" value="Click"/>

FUNCTION SWITCHER

05