Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
How to remove all rows from a table in JavaScript ?
Next article icon

How to remove the table row in a table using JavaScript ?

Last Updated : 14 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Removing a table row in JavaScript involves targeting the row element by its index or unique identifier, then using the remove() method to delete it from the DOM. This updates the table dynamically without requiring a page reload.

This can be done in two ways:

Table of Content

  • JavaScript remove() Method
  • Using DOM deleteRow() method

JavaScript remove() Method

This method removes the selected elements along with text and child nodes. This method also removes data and events of the selected elements. 

Syntax:

node.remove();

Example 1: This example first selects the row by id value and then removes it by using the remove() method. 

html
<!DOCTYPE html> <html lang="en">  <head>     <title>         How to remove the table row          in a table using JavaScript ?     </title>      <style>         table {             margin: auto;         }         table, th, tr, td {             border: 1px solid black;         }     </style> </head>  <body style="text-align: center;">     <h1 style="color:green;">         GeeksforGeeks     </h1>      <h3>         Remove Table Row from a Table     </h3>      <table>         <tr>             <th>S.No</th>             <th>Title</th>             <th>Geek_id</th>         </tr>         <tr id="row1">             <td>Geek_1</td>             <td>GeekForGeeks</td>             <th>Geek_id_1</th>         </tr>         <tr>             <td>Geek_2</td>             <td>GeeksForGeeks</td>             <th>Geek_id_2</th>         </tr>     </table>     <br>      <button onclick="Geeks()">         Click Here     </button>      <script>         function Geeks() {             document.getElementById("row1").remove();         }     </script> </body>  </html> 

Output:

Removing table row using remove() method

Example 2: This example first selects the row by using the tag name and then removes the appropriate element by index using the remove() method. 

html
<!DOCTYPE html> <html lang="en">  <head>     <title>         How to remove the table row          in a table using JavaScript ?     </title>      <style>         table {             margin: auto;         }         table, th, tr, td {             border: 1px solid black;         }     </style> </head>  <body style="text-align: center;">     <h1 style="color:green;">         GeeksforGeeks     </h1>      <h3>         Remove Table row from a Table     </h3>          <table>         <tr>             <th>S.No</th>             <th>Title</th>             <th>Geek_id</th>         </tr>         <tr id="row1">             <td>Geek_1</td>             <td>GeekForGeeks</td>             <th>Geek_id_1</th>         </tr>         <tr>             <td>Geek_2</td>             <td>GeeksForGeeks</td>             <th>Geek_id_2</th>         </tr>     </table>     <br>      <button onclick="Geeks()">         Click Here     </button>      <script>         function Geeks() {             document.getElementsByTagName("tr")[2].remove();         }     </script> </body>  </html> 

Output:

Using DOM deleteRow() method

This method is used for removing an <tr> element from a table.

Syntax:

tableObject.deleteRow(index);

Example: In this example, we will see the use of deleteRow() method.

JavaScript
<!DOCTYPE html> <html lang="en">  <head>     <title>         How to remove the table row          in a table using JavaScript ?     </title>      <style>         table {             margin: auto;         }         table, th, tr, td {             border: 1px solid black;         }     </style> </head>  <body style="text-align: center;">     <h1 style="color:green;">         GeeksforGeeks     </h1>      <h3>         Remove Table row from a Table     </h3>          <table id="newtable">         <tr>             <th>S.No</th>             <th>Title</th>             <th>Geek_id</th>         </tr>         <tr>             <td>Geek_1</td>             <td>GeekForGeeks</td>             <th>Geek_id_1</th>         </tr>         <tr>             <td>Geek_2</td>             <td>GeeksForGeeks</td>             <th>Geek_id_2</th>         </tr>     </table>     <br>      <button onclick="document.getElementById(             'newtable').deleteRow(1)">         Click Here     </button> </body>  </html> 

Output:



Next Article
How to remove all rows from a table in JavaScript ?

P

PranchalKatiyar
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JavaScript-Questions

Similar Reads

  • How to remove table row from table using jQuery ?
    Removing a table row using jQuery involves selecting a specific row within an HTML table and deleting it dynamically. This can be done through various methods like .remove() or .detach(), allowing developers to manipulate the table structure efficiently without reloading the page. Here we have some
    3 min read
  • How to remove all rows from a table in JavaScript ?
    Given an HTML document that contains an HTML table, the task is to remove all rows from the HTML table. Removing all rows is different from removing a few rows. This can be done by using JavaScript.  Here we have two Approaches to removing all rows from a table: Table of Content Using remove() metho
    2 min read
  • How to add table row in a table using jQuery?
    In jQuery, adding a row to a table refers to dynamically inserting a new table row (<tr>) into an existing HTML table. This functionality allows developers to update and manage table content in real-time, enhancing interactivity and user experience without reloading the page. Steps to add tabl
    2 min read
  • JavaScript - How to Sort Rows in a Table?
    Rows in a table are horizontal sections that hold data, organizing information across columns in a structured, easy-to-read format. To sort table rows in JavaScript, create a function that compares rows based on cell values. Use a loop to check and swap rows as needed until all rows are in order. Ap
    4 min read
  • How to select the last row of a table using jQuery ?
    Given an HTML table and the task is to select the last row of the table with the help of jQuery. There are two approaches that are discussed below with the proper example. Approach 1: First, select the table by its ID. Use find() method to find the all table rows of the table. Use last() method to g
    2 min read
  • How to Remove Column from HTML Table using JavaScript ?
    Given an HTML table and the task is to remove the certain column from the HTML table. There are two approaches that are discussed below: Approach 1: First, select the table and also get the rows of table using table.rows. Get the number of columns of a row and go through each one of the columns. Use
    3 min read
  • How to hide the table header using JavaScript ?
    In this article, we will see the methods to hide the table header using JavaScript. There are two approaches that can help to hide a table header with the help of JavaScript. They are discussed below: Using style and display propertyUsing jQuery hide Method Approach 1: Select the header using a CSS
    2 min read
  • How to remove CSS property using JavaScript?
    To remove CSS property using JavaScript, we have different methods. In this article, we will learn how to remove CSS property using JavaScript. Below are the Methods used to remove CSS property using JavaScript: Table of Content Using CSS removePropertyUsing the setProperty methodMethod 1: Using CSS
    2 min read
  • How to make HTML table expand on click using JavaScript ?
    The expandable table can be achieved by using JavaScript with HTML. By Clicking on a row of the table, it expands and a sub-table pops up. When the user again clicks on that row the content will hide. This can be very useful when the data is complex but it is inter-related. Example 1: The following
    5 min read
  • How to remove an HTML element using JavaScript ?
    Removing an HTML element using JavaScript involves deleting it from the DOM, typically using methods like element.remove() or parentNode.removeChild(). This approach updates the webpage dynamically, allowing for responsive interactions by removing unwanted or outdated elements based on user actions
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences