I have a table where each rows has a check box.
This code works for another table:
jQuery('#my_table_id tr').has(':checkbox:checked').closest('tr').each(function() {
request_arr[i] = jQuery(this).attr('id');
i++;
});
Now in this case, I have a table object:
var tbl = $('#my_table') // In my code, this is done dynamically
// This does not work
jQuery(tbl + 'tr').has(':checkbox:checked').closest('tr').each(function() {
request_arr[i] = jQuery(this).attr('id');
i++;
});
How can I get checked rows using a table object like tbl?
I’ve tried various drilldowns, but I can’t get any to work.
Update
This is how I’ve set up my html:
<table id="t1"></table>
<div class="bulk_action">
<div title="Remove requests" class="trash_iconset_grey_16px removeRequest"></div>
<div title="some other button" class="abc"></div>
</div>
<table id="t2"></table>
<div class="bulk_action">
<div title="Remove requests" class="trash_iconset_grey_16px removeRequest"></div>
<div title="some other button" class="abc"></div>
</div>
Clicking the “button” below table 1, will set tbl = <table id="t1">.
@elcanrs solution will also fetch checked rows in table nr 2. I only want checked rows for table nr 1.
jQuery(tbl + 'tr')is the same as$($('#my_table') + 'tr')which makes no sense. Do this instead: