Learn, grow and help others with BBBootstrap
Contribute us with some awesome cool snippets using HTML,CSS,JAVASCRIPT and BOOTSTRAP
One can remove all table rows except one with a given class by using querySelectorAll to fetch all rows, then iterating through the NodeList and checking if the class matches the desired class. If it does not, then remove the row.
// Fetch all rows const rows = document.querySelectorAll('tr'); // Iterate through the rows and remove those that do not have the desired class const className = 'class-name'; rows.forEach(row => { if (!row.classList.contains(className)) { row.remove(); } });