I have a click event on the table row that executes an action. However when I click on the button on the same row, I would like to prevent the on-row-click event and simply
You should remove the click behavior from the TR that that button resides. You can use a jQuery method like $(this).closest('tr')
we can search up from the button through the DOM to find the TR, alternatively you could find the parent using parent functions in jQuery. Once we find the element (TR) we are looking for we can unbind
the click function from it.
So your final call would look like this:
$(this).closest('tr').unbind('click');
I've inserted this into your code and it works as expected, removing the click event from the TR
$(document).ready(function() {
$('#tab_open_deals tbody tr').on('click', function() {
var row = $(' ');
row.load('/echo/html/', {
html: 'Sub1 Sub2 1 2 3 4
'
});
$(this).find(".my_btn").on('click', function(){
$(this).closest('tr').unbind('click');
alert("clicked") })
$(this).find(".my_btn").show();
row.insertAfter($(this));
});
});
I hope this works well for you.