jquery, trying to bind event to tr but it's also applied to child elements
I'm trying to add a row click event on a table populated by json data. The row click itselves works but it's also applied to child elements such as checkboxes and buttons which are in the row cells.
$('#results tbody tr').live("click",function(){
})开发者_JAVA技巧;
That's the way i'm selecting the table row, maybe i'm missing something very obvious here? Probably!
Thanks for your time! regards, Mark
Basically, if you don't handle the clicks coming from the sub-elements (or cancel their propagation) they will bubble up to the tr
Either do something to return false;
on sub-element clicks to stop the event propagation, or view the event coming in to your function above, an see what triggered it, if it was a sub-element, ignore it.
Prevent input and checkbox click events from bubbling up.
$('#results tbody tr:input', '#results tbody tr:checkbox').live("click",function(event){
event.stopPropagation();
});
精彩评论