HOW TO remove columns from a table using JavaScript in the browser's Developer Console

The Developer Console of your web browser (invoked through the keyboard shortcut F12) allows you to manipulate the Document Object Model (DOM) of any web page that you have loaded in your browser. 

Developer Console
Microsoft Edge Developer Console

This powerful tool enables you to explore, edit, and experiment with the HTML, CSS, and JavaScript code of any web page, providing you with unprecedented control over the elements that make up a website.

Let's say you want to remove the last 2 columns of a 3-column table using JavaScript in the browser's developer console, paste this code & see the columns vanish -

// Select all table rows

const rows = document.querySelectorAll('table tr');

// Iterate through each row

rows.forEach(row => {

  // Remove the last cell twice

  row.removeChild(row.lastElementChild);

  row.removeChild(row.lastElementChild);

});

Comments

Popular posts from this blog

HOW TO Read Linux ext4 Files on Windows with 7-Zip (No Drivers Needed)

20 SQL Server 2005 Keyboard Shortcuts

The Diet Delinquent