Sometimes, we want to disable click with JavaScript.
In this article, we’ll look at how to disable click with JavaScript.
How to disable click with JavaScript?
To disable click with JavaScript, we set the onclick
property to a function that returns false
.
For instance, we write
document.getElementById("myElement").onclick = () => {
return false;
};
to select the element with getElementById
.
Then we set its onclick
property to a function that returns false
.
The function is called when we click on the element.
And it returns false
to stop the default click action.
Conclusion
To disable click with JavaScript, we set the onclick
property to a function that returns false
.