// Using CSS (prefered) #foo { pointer-events: none; } //Using JS const clickable = true; document.getElementById("foo").onclick = () => { if (clickable) { //...your code } }