简体   繁体   中英

how can I find the checkbox element in the same td element using its class name

I have two column in a table one with checkbox and another is Input element. I am trying to find the checkbox element from javascript and to get checked from javascript. Here is my code

 var chbox = $(this).closest('tr').find('.nhrs a').empty(); // simillarly I have to find checkbox element and to set its checked property =true
 <table> <tbody> <tr> <td> <input asp-for="@Model.attendanceLogList[i].IsProtected" type="hidden" /> <input type="checkbox" value="true" disabled asp-for="@Model.attendanceLogList[i].IsNormalAttendance" data-tag="NormalHrs" /> <input type="hidden" value="false" asp-for="@Model.attendanceLogList[i].IsNormalAttendance" /> <input asp-for="@Model.attendanceLogList[i].IsClockingEnabled" type="hidden" /> </td> <td class="nhrs"> <a href="#" class="disabled" data-pk="NormalHrs">@Model.attendanceLogList[i].NormalHrs</a> <input asp-for="@Model.attendanceLogList[i].NormalHrs" type="hidden" class="bros" /> </td> </tr> </tbody> </table>

You can find your checkbox by writing query .find('input[type="checkbox"]')

You mean

$(this).closest("tr").find("[data-tag=NormalHrs]").prop("checked",true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM