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

Workshop Highlights - Build AI Apps using Google AI Studio & Gemini AI

A Beginner's Guide to Data & Analytics - Highlights

AI - Reflections & Perspectives