JSFiddle - React, Tailwind, and code Playground

by ChrisStanyon

HTML

<table style="width: 576px;">
<tbody>
  <tr style="height: 13px;">
    <td style="width: 576px; height: 13px;"></td>
  </tr>
  <!--some other comment-->
  <tr style="height: 13px;">
    <td style="width: 576px; height: 13px;"></td>
  </tr>
  <!--for input in inputs-->
  <tr id="testelement" style="height: 13px;">
    <td style="width: 576px; text-align: center; height: 13px;">loop this line</td>
  </tr>
  <!--endfor-->
  <tr style="height: 13px;">
    <td style="width: 576px; height: 13px;"></td>
  </tr>
</tbody>
</table>
<button id="remove">Remove Comments</button>

JavaScript

$('#remove').click(function(e) {

// Get the comments within the tbody
$("tbody").contents().filter(function(){
  return this.nodeType == 8;
}).each(function(i, e){
	// Loop through them and check if it comes before or after the #testelement
	if ($(e).prev('#testelement').length || $(e).next('#testelement').length)
    $(e).remove();
});

});