Avdhut Vaidya Avdhut Vaidya - 3 months ago 12
Javascript Question

Disconnecting click event of parent node using jQuery

I have a

<td>
which contains a
<span>
tag. The td tag has a click event and the
<span>
tag has an id. On clicking the span, I want to disconnect the click event of the
<td>
tag. How do I do by referring to the span tag?

<Table>
<tr>
<td onClick="disconnectHandler();"><span id="testin">Hello</span></td>
</tr>
</Table>


This is what my JavaScript has :

function disconnectHandler()
{
alert("Hi Hello");
$("#testin").parent().unbind();
}


It keeps showing the alert box. What is wrong with this code?

Additionally, i want to attach the click event to it later too after removing it!

Answer

this can also be tried

function disconnectHandler()
{
    alert("Hi Hello");
    $("#testin").parent().attr('onclick',"")
}