Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the onclick event once it happens?

I had a image which calls add_cart() JavaScript function when onclick()

<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, add_cart function should be called. If he clicks second time no event should happen.

like image 501
Rajasekar Avatar asked Aug 09 '10 08:08

Rajasekar


2 Answers

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

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

Cheers

like image 176
igauravsehrawat Avatar answered Oct 03 '22 09:10

igauravsehrawat


<img src="images/add.png" onclick="add_cart(); this.onclick=null;">
like image 41
Anurag Avatar answered Oct 03 '22 09:10

Anurag