Rajasekar Rajasekar - 1 year ago 74
HTML Question

How to disable the onclick event once it happens?

I had a image which calls

JavaScript function when

<img src="images/add.png" onclick="add_cart()">

I want the user to click the image only one time. When the user clicks it first time,
function should be called. If he clicks second time no event should happen.

Answer Source

If you are dealing this on jquery side,you can use jquery one method

$(".myDiv").one("click", function(){  
    alert("this will happen only once");