bobMartin2nd
bobMartin2nd

Reputation: 21

trying to use a jQuery to remove specific text from a td

Im trying to make it so when the first column is clicked the N next to each checkbox goes away so far I have tried 2 different methods the first was nextsilbing.remove but that just removed the row I clicked on. The second method I tried was this.nextAll and removed everything but the row clicked.

[picture of table][1]

 $('#table_output tbody').on('click', 'tr', function() {
      console.log(table.row(this).data());
      alert(JSON.stringify(table.row(this).data()));
    })
$('#table_output tbody').on('click', 'td', function() {
      console.log(table.cell(this).data());
      while (this.nextSilbing){
          this.nextSibling.remove("N")
      }
      alert("Test" + table.cell(this).data());
      
      //second method
      $(this).nextAll().remove("N").end().remove();
    })

<table>
  <tr>
    <th>Carrier</th>
    <th>fixed</th>
    <th>mobile</th>
    <th>payphone</th>
  </tr>
  <tr>
    <td>Cat066</td>
    <td><input type="checkbox" name="Fixed" ::before "N" />&nbsp;</td>
    <td><input type="checkbox" name="Mobile" ::before "N" />&nbsp;</td>
    <td><input type="checkbox" name="PayPhone" ::before "N" />&nbsp;</td>
  </tr>
</table> ```


  [1]: https://i.sstatic.net/vUSKM.png

Upvotes: 0

Views: 37

Answers (1)

Jam
Jam

Reputation: 584

I’d try to put the :before in a css class instead, and toggle the class with JQ.

// css
.input.n:before {
    content: “N”;
}

// js
// assuming `this` is the input element
$(this).toggleClass('n');

Apologies if the syntax is a bit wrong, I’m on mobile ;) correct me in the comments

Upvotes: 1

Related Questions