0

I have the following HTML:

<td aria-describedby="26c980b7-c0e9-416d-b904-5f7454ac67a5" role="gridcell">
    <input type="checkbox" onclick="onReeferPopup(event)" checked="checked" name="reefer">
    NOR
</td>

I have a js function in which I have the td-element. How do I remove the text 'NOR' and KEEP the checkbox?

tdElement.prop("innerHTML", "");
tdElement.prop("textContent", "");
tdElement.prop("outerText", "");

All remove the the text AND the checkbox

Kip ei
  • 479
  • 6
  • 20

1 Answers1

0

Since NOR isn't in its own element, use replace on the returned html value.

var tdInput = $('td[role="gridcell"] input');
$('td[role="gridcell"]').html(tdInput);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <thead></thead>
  <tbody>
    <td aria-describedby="26c980b7-c0e9-416d-b904-5f7454ac67a5" role="gridcell">
      <input type="checkbox" onclick="onReeferPopup(event)" checked="checked" name="reefer">
      NOR
    </td>
  </tbody>
</table>
Josh
  • 1,455
  • 19
  • 33