How to check all checkboxes in a specific javascript column?

Say I have a table with 3 columns, only the 1st and 3rd columns of TDs have checkboxes. I have a button that says โ€œSelectAllFirstโ€, which only selects the checkbox in the first column, the third one remains unskilled. How to do it?

I thought it would be something like this:

$("#mytable tr td:eq(0) input:[type=checkbox]").prop("checked", true); 

(but it does nothing. Removing "eq (0)" causes all the checkboxes, including the third column to check)

+4
source share
3 answers

I think this should work, although I have not tried:

 $("#mytable tr td:nth-child(1) input[type=checkbox]").prop("checked", true); 
+5
source

td is a cell, I think you mean a string. It's hard to say without html though ...

 $("#mytable tr:eq(0) td input:checkbox").prop("checked", true); 
0
source

I created a fiddle for you: http://jsfiddle.net/pwCKu/

I believe that there are better ways to switch a check. Just a proof of concept.

0
source

Source: https://habr.com/ru/post/1412223/


All Articles