1

I am using onClick event for the image.

When I am disable for the particular case, I didn't know exactly how can disable the onClick functionality using JavaScript.

Sample code:

<td>
    <a onClick="fun()">
        <html:img src="/caleder.jpg ... />
    </a>
</td>

calling fun:

function fun() {
    // in fun I want to disable the img and onClick functionality
    // i.e when I click that img, then it can't perform the onClick event.
}

4 Answers 4

3

The probably most efficient way since it removes the event listener:

<script>
  function fun(node) {
    document.getElementById(node).removeAttribute("onClick");
  }
</script>

Inside of the onClick() you need to place a this so it would be onClick(this)

Sign up to request clarification or add additional context in comments.

Comments

1

I usually just set a variable and put the events in the onClick handler inside a conditional statement. Set the variable on the first click, and next time it won't fire.

<script>
  var i = 0;
  function clickHandle(){
    if(i==0){
       //do stuff
       i=1;
  }
<script>

Comments

1

you can easy handle this issue with this code after you function see this codes

function disableClick() {
   document.getElementById('yourId you want disable on click').onclick = "";
}

and enable same this code

Comments

0

The best way IMO.

function fun() 
{
    if (this.clicked == undefined)
    {
        this.clicked = true;
        // have fun
    }
    return false;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.