jquery - How do I focus on an input inside a table cell? -
i have inputs inside table cells
<td alt="" class="timesheet-highlight"><input type="text" id="c6r1" name="c6r1" size="7" value="0.00" class="form-control"></td>
when tab onto table cell applied class timesheet-highlight
. having trouble figuring out how focus input inside cell. there multiple inputs in table , id's generated dynamically there no way know be. cells may not have inputs.
i can fire event when tab onto cell this
.on('key-focus', function (e, datatable, cell) { if ($('td').hasclass('timesheet-highlight')) { alert('hi'); } });
i using datatables , full code generate said table:
$(document).ready(function () { var grid = $('#tbltimesheet').datatable({ "scrolly": "567px", "paging": false, "sscrollx": "100%", keys: { classname: 'timesheet-highlight' } }); grid .on('key-focus', function (e, datatable, cell) { if ($('td').hasclass('timesheet-highlight')) { alert('hi'); } }); /*.on('key-blur', function (e, datatable, cell) { $('#details').html('no cell selected'); });*/ });
the .on('key-focus'.... function has cell parameter cell on focus on.
by invoking cell.node() 'td' element if understand correctly, want this:
.on('key-focus', function (e, datatable, cell) { var inputfieldinselectedtd = $(cell.node()).find('input'); if (inputfieldinselectedtd) { inputfieldinselectedtd.focus(); } });
Comments
Post a Comment