javascript - Can't focus on a <td> element in my table on click event -
i have table , when click on button want set contenteditable true, do, , put focus on td element client sees cursor blinking in cell.
i can't seem focus work on licensename cell. know 'tabledata' variable contains correct element, i've checked in browser debugger.
here i've tried.
editlicensesdetails = function (e) { var tablerow = $(e.target).parent().parent(); $(tablerow).css('background-color', '#dff0d8'); $(tablerow).children('[contenteditable]').attr("contenteditable", "true"); var tabledata = $(tablerow).children('[contenteditable]')[0]; $(tabledata).focus(); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table id="tablelicensedetails" style="width:100%;"> <tr> <th>edit</th> <th>delete</th> <th>name</th> <th>description</th> <th>product</th> <th>unit of measure</th> <th>variable rate</th> </tr> <tr> <td style="display:none;">@license.licenseid</td> <td> <i class="fa fa-pencil" aria-hidden="true"></i> </td> <td> <i class="fa fa-trash" aria-hidden="true"></i> </td> <td contenteditable="false">@license.licensename</td> <td contenteditable="false">@license.licensedescription</td> <td>@license.tradepulseproductname</td> <td>@license.licenseunitofmeasuretypename</td> <td>@license.isvariablerate</td> </tr> </table>
your code working correctly. means wrong when calling editlicensesdetails function
var tablerow = $('tr'); $(tablerow).css('background-color', '#dff0d8'); $(tablerow).children('[contenteditable]').attr("contenteditable", "true"); var tabledata = $(tablerow).children('[contenteditable]')[0]; $(tabledata).focus();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tr> <td contenteditable="false">licensename</td> <td contenteditable="false">licensedescription</td> </tr> </table>
Comments
Post a Comment