Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To remove a table cell when its text exactly matches a value, select the td elements, compare each cell’s text, and call remove() on matches:

document.querySelectorAll('td').forEach((cell) => {
  if (cell.textContent.trim() === 'remove') {
    cell.remove();
  }
});

This removes the matching cell element—not just the text inside it. The example trims surrounding whitespace before checking for an exact match.

Remove matching cells in the whole document

document.querySelectorAll('td') selects every table cell in the document. The loop checks each cell’s text and removes only those that match the target. querySelectorAll() returns a static NodeList, so removing cells while iterating does not change the collection being traversed.

const target = 'remove';

document.querySelectorAll('td').forEach((cell) => {
  if (cell.textContent.trim() === target) {
    cell.remove();
  }
});

MDN’s querySelectorAll() reference describes the returned static NodeList. Element.remove() removes the cell from its parent.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the right text comparison

Exact match

cell.textContent.trim() === target matches only when the cell’s text, after trimming leading and trailing whitespace, equals the target. Remove .trim() if surrounding whitespace should count as part of the value.

Substring match

To remove a cell when it contains the target anywhere in its text, use includes() instead:

if (cell.textContent.includes(target)) {
  cell.remove();
}

Equality and substring matching are different rules: for a target of remove, the exact comparison does not match please remove, while includes() does.

Text content or rendered text

textContent reads text in the cell and its descendants, including text that may be hidden. If the condition should reflect rendered text instead, use innerText. See MDN’s textContent documentation for the distinction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Limit the search to one table

If the page has several tables, scope the query to the intended table rather than checking every cell:

const table = document.querySelector('#results');

if (table) {
  table.querySelectorAll('td').forEach((cell) => {
    if (cell.textContent.trim() === 'remove') {
      cell.remove();
    }
  });
}

Replace #results with the selector for your table. The null check prevents an error if no matching table exists.

Run the code after the cells exist

For cells already present in the page, run the code after the document has been parsed—for example, from a script loaded with defer, or in a DOMContentLoaded handler. If application code adds or updates cells later, run the matching logic after those changes; an initial query does not automatically process future cells.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check whether removing one cell preserves the intended table

Removing a single td changes the table’s structure. Depending on the row, column, and any colspan or rowspan attributes, the remaining cells may no longer line up as intended. Choose the operation that matches the result you want:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Remove just the cell: call cell.remove().
  • Keep the cell but empty it: set cell.textContent = ''.
  • Remove the whole row: call cell.closest('tr')?.remove() when the matching cell should make its entire row disappear.
  • Keep the table grid aligned: inspect whether a neighboring cell needs a different span; the correct change depends on the table markup.

The question of removing a cell by its text was raised in a SitePoint Community discussion on September 6, 2020. Its original poster clarified that they wanted to remove the actual cell, rather than merely clear its contents. The JavaScript approach above directly handles that case.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.