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
  • jQuery Tutorial
  • jQuery Selectors
  • jQuery Events
  • jQuery Effects
  • jQuery Traversing
  • jQuery HTML & CSS
  • jQuery AJAX
  • jQuery Properties
  • jQuery Examples
  • jQuery Interview Questions
  • jQuery Plugins
  • jQuery Cheat Sheet
  • jQuery UI
  • jQuery Mobile
  • jQWidgets
  • Easy UI
  • Web Technology
Open In App
Next Article:
How to remove the table row in a table using JavaScript ?
Next article icon

How to remove table row from table using jQuery ?

Last Updated : 24 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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 common approaches to remove table row from table using jQuery :

Table of Content

  • Using .remove() Method
  • Using .detach() Method

Approach 1: Using .remove() Method

The .remove() method in jQuery allows you to delete a specific row from an HTML table by selecting it with a jQuery selector. This completely removes the row and its content from the DOM, without leaving any trace.

Syntax

$(selector).remove(selector)

Example : In this example we removes a specific table row with the ID row1 using the jQuery .remove() method. When the button is clicked, the first row of the table is deleted.

html
<!DOCTYPE HTML> <html>  <head>      <title>         How to remove a table row         from table     </title>      <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js">     </script>      <style>         #myCol {             background: green;         }          table {             color: white;         }          #Geek_p {             color: green;             font-size: 30px;         }          td {             padding: 10px;         }     </style> </head>  <body>     <center>         <h1 style="color:green;">             GeeksForGeeks         </h1>          <table>             <colgroup>                 <col id="myCol" span="2">                 <col style="background-color:green">             </colgroup>              <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 to remove table row from table -->         <script>             function Geeks() {                 $("#row1").remove();             }         </script>     </center> </body>  </html> 

Output:

Deleting-table-row
Using .remove() Method to remove table row from table

Approach 2: Using .detach() Method

The .detach() method in jQuery removes a table row from the DOM while keeping the row's data and events in memory. This allows for temporary removal and potential reinsertion of the row at a later time.

Syntax:

$(selector).detach()

Example: In this example we removes a table row with the ID row1 using the jQuery .detach() method. The row is stored in memory for possible reinsertion when the button is clicked.

HTML
<!DOCTYPE HTML> <html>  <head>      <title>         How to remove a table row         from table     </title>      <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js">     </script>      <style>         #myCol {             background: green;         }          table {             color: white;         }          #Geek_p {             color: green;             font-size: 30px;         }          td {             padding: 10px;         }     </style> </head>  <body>     <center>         <h1 style="color:green;">             GeeksForGeeks         </h1>          <table>             <colgroup>                 <col id="myCol" span="2">                 <col style="background-color:green">             </colgroup>              <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 to detach table row from table -->         <script>             let detachedRow;              function Geeks() {                 // Detach row1 but keep it in memory                 detachedRow = $("#row1").detach();               }         </script>     </center> </body>  </html> 

Output:

Deleting-table-row
Using .detach() Method to remove table row from table

jQuery is an open source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous with it's philosophy of “Write less, do more". You can learn jQuery from the ground up by following this jQuery Tutorial and jQuery Examples.


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

P

PranchalKatiyar
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JQuery
  • jQuery-Misc

Similar Reads

  • 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
  • How to Dynamically Add/Remove Table Rows using jQuery?
    We will dynamically add/remove rows from an HTML table using jQuery. jQuery provides us with a lot of methods to perform various tasks. To dynamically add and remove the rows from an HTML table, we are also going to use some of these jQuery methods like append(), remove(), etc. Adding a rowTo add a
    3 min read
  • How to remove the table row in a table using JavaScript ?
    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() Me
    3 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 select all even/odd rows in table using jQuery ?
    In this article, we will see how to make a table by selecting the alternate rows i.e. selecting the even or odd rows by clicking on the respective buttons. This feature can be useful at the time of selecting the specific data/elements of either of the rows or to highlight the table of data for displ
    3 min read
  • How to remove options from select element using jQuery ?
    Removing options from a select element using jQuery means programmatically deleting specific or all <option> elements within a <select> dropdown. This can be done using jQuery methods like remove() or empty(), allowing dynamic updates of the dropdown's available choices based on conditio
    3 min read
  • How to Delete All Table Rows Except First One using jQuery?
    To delete all table rows except the first one using jQuery, you can target the rows and remove them while keeping the first row intact. ApproachFirst, we create a table using <table> tag and add a button containing btn id. When a user clicks on the button, then the jQuery function is called. T
    1 min read
  • How to remove all paragraphs from the DOM using jQuery ?
    To remove elements and content, we use jQuery remove() method which removes the selected element as well as everything inside it, also it will remove all bound events associated with that target element. Syntax: $(selector).remove() Example : C/C++ Code <!DOCTYPE html> <html> <head
    1 min read
  • How to remove specific value from array using jQuery ?
    Given an array elements and the task is to remove the specific value element from the array with the help of JQuery. There are two approaches that are discussed below: Approach 1: We can use the not() method which removes the element that we want. Later, use get() method to get the rest of the eleme
    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
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