tags:

views:

28

answers:

3

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.
}
A: 

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>
Orbit
A: 

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)

Glenn Nelson
A: 

The best way IMO.

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