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

Maven Crash Course - Learn Power Query, Power Pivot & DAX in 15 Minutes

"Data Prep & Exploratory Data Analysis" course by Maven Analytics

Oracle Cloud Infrastructure 2024 Generative AI Professional Course & Certification Exam (1Z0-1127-24)