locked
how can I find the element inside the td element using the class name RRS feed

  • Question

  • User-1355965324 posted

    I am trying to make empty the value of an anchor tag  inside the td  element with class name. Here is the code. In my Example . If i click the checkbox, then  immediately make empty the anchor tag having class 'nhrs'

    <td><input asp-for="@Model.attendanceLogList[i].IsProtected" type="hidden" /><input type="checkbox" value="true" 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="#" data-pk="NormalHrs">@Model.attendanceLogList[i].NormalHrs</a><input asp-for="@Model.attendanceLogList[i].NormalHrs" type="hidden" class="bros" /></td>
    <td><input type="checkbox" value="true" asp-for="@Model.attendanceLogList[i].IsSickMarked" data-tag="SickHrs" /> <input type="hidden" value="false" asp-for="@Model.attendanceLogList[i].IsSickMarked" /></td>
    <td><a href="#" data-pk="SickHrs">@Model.attendanceLogList[i].SickHrs</a><input asp-for="@Model.attendanceLogList[i].SickHrs" type="hidden" class="bros" /></td>
    <script>
    $("input:checkbox").on('click', function () {
    var $box = $(this);
    $box.parent('td').next('td').find('a').empty();  // I have to make empty the anchor tag value inside the td having the class nhrs
    })
    

    Wednesday, February 17, 2021 7:32 PM

Answers

  • User-1355965324 posted

    After i change  the code into 

     $(this).closest('tr').find('.nhrs a').empty();

    it is working fine

    thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 17, 2021 9:16 PM

All replies

  • User-474980206 posted

    You should read the jquery documentation on selectors. It’s a simple:

    $box.parent('tr').find('td.nhrs a').empty(); 

    Wednesday, February 17, 2021 7:44 PM
  • User-1355965324 posted

    I tried but that is not working 

    Wednesday, February 17, 2021 9:00 PM
  • User-1355965324 posted

    After i change  the code into 

     $(this).closest('tr').find('.nhrs a').empty();

    it is working fine

    thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 17, 2021 9:16 PM
  • User475983607 posted

    polachan

    I tried but that is not working 

    polachan, I provided the same selector in your other threads on this subject.  Take the time to learn the basics.

    $("input:checkbox").click(function () {
        var a = $(this).closest('tr').find('.nhrs a').empty();
    });

    Wednesday, February 17, 2021 9:41 PM