0

I am getting a table element for a given row in the table using the following code in jQuery 1.8.2.

var tbl = $("input[id$='chkSelectAll']").closest('table'); 

Now, I want to replace the JavaScript code below with corresponding jQuery script. What would be the jQuery for this code below?

It would be nice if I could just get the table rows as an array from the above tbl variable in jQuery, as that would solve my problem.

 for (var i = 1;i < tbl.rows.length - 1;i++) { var chk = tbl.rows[i].cells[0].firstChild; //we have a checkbox in first cell of every row chk.checked = chkAll.checked; } 

1 Answer 1

1
 var rows = $('tr', tbl); for (var i = 1;i < rows.size() - 1; i++) { rows.eq(i).find('td:first').find('input:checkbox').prop('checked', true ); } 

You can use "chkAll.prop('checked')" instead of "true" assuming that you have chkAll as jQuery object of that checkbox

Sign up to request clarification or add additional context in comments.

6 Comments

Michael - Thanks. What is eq(i)? Probably, the element at i.
Michael - There is one problem wit your code. In FF and IE 10. I get as undefined for this expression: $("input[id$='chkSelectAll']").closest('table').find('tr').eq(1).find('td:first').find('checkbox').attr('id')
Try to break it down into many lines so you can know which one is not working.. Or if you could post a new question with jsFiddle would be better
I think the problem in expression is .find('checkbox'). May be it should be .find('input') as there is no element of checkbox type. A checkbox is of input type. Right?
So I think the problem is .find('checkbox') should be either .find('input:checkbox') Or .find('input') since there is only one input element in first cell of the row.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.