Possible Duplicate:
jQuery – on() function when a div is clicked, but not when a child of that div is clicked
$(oTrPlanning).prev().children('td').each(function () {
this.onclick = setCountClick;
});
On click of TD setCountClick() is called but TD also contains a Textbox:
<td>
<input class="Input-InlineFilter" id="TextFirst" type="text" value="">
</td>
So, when I start typing something on Textbox, setCountClick() is again called.
I want to call setCountClick() when TD is clicked, but not Textbox.
The click event bubbles up the DOM from the
textboxto thetd, all the way tobody. If you don’t wanttextboxclicks to trigger thetdclick handler, you need to stop the bubbling:Documentation for stopPropagation
To expand, you should be taking advantage of this bubbling to only bind one event handler for all
tds:Documentation for nodeName
Be aware that if you are relying on the
thisoperator anywhere inside ofsetCountClick, it may no longer work as expected. To fix that you would need to look into using$.proxyorbindwhen you callsetCountClick:bindreturns a new function that uses the argument you pass as thethisparameter inside the new function. Then you execute that function and pass it your regular parameters.Documentation for bind