Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making table rows but not table headers clickable in jquery

Currently I am using

$('#mytable tr').click(function() {
    blah blah
});

This makes all rows, including the headers clickable. How can I exclude the headers or <th>'s?

like image 600
lodkkx Avatar asked Dec 30 '25 16:12

lodkkx


1 Answers

Separate you header and body using <thead> and <tbody> tags, and change your selector to "#mytable tbody tr"

HTML will look something like this

<table> 
    <thead>
        <tr>
         ...
        </tr>
    </thead>
    <tbody>
         <tr>
            ...
         </tr>
    </tbody>
</table>
like image 185
Olegas Avatar answered Jan 02 '26 04:01

Olegas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!