4

Say I have a table with 3 columns, only the 1st and 3rd column of TDs have checkboxes. I have a button that says "SelectAllFirst" that puts a checkmark on all checkboxes in the first column only, the 3rd remains uncheked. How do I accomplish this?

I thought it would be something like this:

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

(but that doesnt do anything. Removing the "eq(0)" results in all checkboxes including the 3rd column to be checked)

1
  • what about removing the colon from between input and the square brackets? Commented May 13, 2012 at 6:10

4 Answers 4

6

I think this should work,though I didnt try it out:

$("#mytable tr td:nth-child(1) input[type=checkbox]").prop("checked", true);
Sign up to request clarification or add additional context in comments.

Comments

0

td is the cell, I guess you mean the row. Hard to tell without html though...

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

Comments

0

I've created a Fiddle for you here: http://jsfiddle.net/pwCKu/

I believe there are better ways to toggle the check. Just a proof of concept.

1 Comment

i misunderstood the question. sorry. :D
0
  $("#checkAll").click(function () {
$(".check").prop('checked', $(this).prop('checked'));

});
This is the code for checking all checkboxes with a checkbox like "select all".

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.