You can use something like
Demo
$(window).on('click', '.mybutton' ,function() {
alert($(this).parent().parent().find('.nr').text());
//Or you can use, which is even better
//alert($(this).parent().siblings('.nr').text());
});
Here, the selector is pretty simple, we are first binding click
event on the button, and onclick
we select the button
element parent i.e td
and we select the parent of td
i.e tr
and later we find an element with a class
of .nr
You can also write td.nr
instead of just .nr
to be more specific.
Your rows are being dynamically added, in order for your click listener to work you will have to delegate the events
Credits to @Patsy Issa for suggesting .siblings()