Steven
Steven

Reputation: 25294

How to change an element to be unclickable after clicking it once using Jquery or Javascript

The code is:

<a href="#" style="color:black" onClick="Record($id)">Done</a>  

I want this part becomes unclickable once if it is clicked, how to achieve this using Jquery or Javascript?

Upvotes: 2

Views: 860

Answers (2)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 195992

Use the .one() method which does exactly that ..

$(document).ready(function(){

   $('#anch1').one('click', function() {
      Record(/* your parameter */);
    });

});

Upvotes: 5

rahul
rahul

Reputation: 187040

Provide the anchor tag an id and remove the onclick handler from the HTML markup.

<a id="anch1" href="#" style="color:black">Done</a>  

$(function(){
    $("#anch1").bind("click",function(){
        // do your action here
        $(this).unbind("click"); //unbinds the click event
    });
});

Upvotes: 1

Related Questions