Free tools Windows power users keep installed
One-click scans. No signup required.
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.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute#1 Best Overall
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:
Rank #2
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.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →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.
Rank #4
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.
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:
Recommended Free Tools
Best Value
- 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.
Quick Recap
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.

