I would like to make my table row clickable. All of the columns need to be clickable but the first one. However I would like to achieve this when they are clicking on the row.
This is the code I have so far:
$('.table tbody tr').click( function (e) {
alert ($(this).find('td').eq(1).text());
} );
This code executes always no matter where I click in the row. However I'd like that all of the table cells should be clickable except the first one.
Is it possibe?
You could do something like this:
$('.table tbody tr').on('click', function(e) {
if ($(e.target).closest('td:first-child').length) {
return;
}
// your code
});
This says "if the clicked element is a td:first-child
or has an ancestor that is a td:first-child
, do nothing; otherwise continue."
jsFiddle
Use the CSS Not selector and skip first tr element:
$('.table tbody tr:not(:first-child)').click( function (e) {
alert ($(this).find('td').eq(1).text());
} );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With