I would like to select all cells of the first column of a table. Can anyone please tell me the code.
Tried this..
$('.sortable tr:nth-child(1)'); // getting entire row.
Columns can be selected using column(). select() or columns(). select() API methods. You can enable single or multiple items selection using select.
The colvis button type provides a columns option to allow you to select what columns should be included in the column visibility control list. This option is a column-selector and thus a number of methods to select the columns included are available including jQuery selectors and data index selectors.
In Mozilla Firefox, users may highlight only certain rows, columns, or cells of an HTML table by holding down the Ctrl on the keyboard and click each cell individually.
Description. The columns option in the initialisation parameter allows you to define details about the way individual columns behave. For a full list of column options that can be set, please see the related parameters below.
This (fairly verbose) selector should work:
$(".sortable tr > :nth-child(1)")
If you want another column, simply change the index to nth-child
to something other than 1
.
This will select both td
(data) and th
(header) cells, btw.
$(".sortable tr > :nth-child(1)")
.css("background-color", "yellow");
<table class="sortable">
<tr> <th> A </th> <th> B </th> <th> C </th> </tr>
<tr> <td> 1 </td> <td> 2 </td> <td> 3 </td> </tr>
<tr> <td> 10 </td> <td> 20 </td> <td> 30 </td> </tr>
<tr> <td> 100 </td> <td> 200 </td> <td> 300 </td> </tr>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
$('.sortable td:first-child');
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