Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery select column

Tags:

jquery

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.
like image 330
Atif Avatar asked Jan 25 '10 12:01

Atif


People also ask

How to select a column using jQuery?

Columns can be selected using column(). select() or columns(). select() API methods. You can enable single or multiple items selection using select.

How to select a column in datatable?

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.

How to select a specific column in html table?

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.

WHAT IS columns in jQuery Datatable?

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.


2 Answers

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>
like image 192
stakx - no longer contributing Avatar answered Sep 24 '22 15:09

stakx - no longer contributing


$('.sortable td:first-child'); 
like image 32
kgiannakakis Avatar answered Sep 20 '22 15:09

kgiannakakis