Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:18:53+00:00 2026-06-17T08:18:53+00:00

I have a table. At the end of each row tehere is a href

  • 0

I have a table. At the end of each row tehere is a href “X” which deletes this row. This is pretty simple. Now when you click “X” for any row 2 it deletes row 2, but then when you click on row 3 it deleted row 4.

This is my code:

HTML

<table id="my_table" align="center" cellspacing="0" cellpadding="0" border="0">
  <tr>
    <td>Custom0</td>
    <td><a title="my title text" id="1" href="#" class="someclass" onclick="deleteRows(0)">X</a>

    </td>
  </tr>
  <tr>
    <td>Custom1</td>
    <td> <a title="my title text" id="2" href="#" class="someclass" onclick="deleteRows(1)">X</a>

    </td>
  </tr>
  <tr>
    <td>Custom2</td>
    <td> <a title="my title text" id="3" href="#" class="someclass" onclick="deleteRows(2)">X</a>

    </td>
  </tr>
  <tr>
    <td>Custom3</td>
    <td> <a title="my title text" id="4" href="#" class="someclass" onclick="deleteRows(3)">X</a>

    </td>
  </tr>
  <tr>
    <td>Custom4</td>
    <td> <a title="my title text" id="5" href="#" class="someclass" onclick="deleteRows(4)">X</a>

    </td>
  </tr>
  <tr>
    <td>Custom5</td>
    <td> <a title="my title text" id="6" href="#" class="someclass" onclick="deleteRows(5)">X</a>

    </td>
  </tr>
</table>

and Javascript

function deleteRows(row) {
  var tbl = document.getElementById('my_table'); // table reference
  tbl.deleteRow(row);
}

You can play wit it here: http://jsfiddle.net/nTJtv/13/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:18:54+00:00Added an answer on June 17, 2026 at 8:18 am

    You have hard-coded the row numbers, so after the first deletion they are out of sync. The <table> element’s .rows property is “live”, so removing one means the numbers no longer line up with your HTML.

    Instead, consider passing this.parentNode.parentNode to the function and using it to determine which row to delete:

    <a title="my title text" id="6" href="#" class="someclass" onclick="deleteRows(this.parentNode.parentNode)">X</a>
    

    Then use removeChild() in the function:

    function deleteRows(row) {
      var tbl = document.getElementById('my_table'); // table reference
      tbl.getElementsByTagName("tbody")[0].removeChild(row);
    }
    

    Edit: The <tr> is a child of the <tbody> element, so that must be the parent from which it is removed.

    http://jsfiddle.net/nTJtv/19/

    If you would really rather do it with deleteRow(), then loop through the rows to find the one passed to the function and delete it:

    function deleteRows(row) {
      var tbl = document.getElementById('my_table'); // table reference
      // Loop over the table .rows collection to find the one passed into the function
      for (var i=0; i<tbl.rows.length; i++) {
        if (row == tbl.rows[i]) {
          // And delete it
          tbl.deleteRow(i); 
          return;
        }
      } 
    }
    

    http://jsfiddle.net/nTJtv/21/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table, and at the end of each row, there is a
I have a table in an ASP.NET MVC2 form. On each row in the
I have a table, where each row has a timestamp. The timestamp is a
I have a table which has an nvarchar column. The strings stored in this
I have a table design, used by recruiter to upload profiles. Each row contains
I have a html table with form elements in each row to add items,
I have periods table that has start_at:datetime end_at:datetime . Because each period begins and
My table have data structure like this cate_id task_id date_start date_end other 34 14
I have the following table in my view. <table> <tr> <th>Name</th> <th>Start</th> <th>End</th> </tr>
I have table in which I am inserting rows for employee but next time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.