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 808189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:31:24+00:00 2026-05-15T00:31:24+00:00

I am using insertRow to insert a TR element into a table, but for

  • 0

I am using insertRow to insert a TR element into a table, but for some reason it doesn’t count that inserted TR element as a sibling of the others when I do nextSibling on it.

For example, consider the following table.

<table id="myTable">
    <tr id="row_0">
        <td colspan="3">Row 1</td>
    </tr>
    <tr id="tr_0_0">
        <td>Option 1</td>
        <td>Option2</td>
        <td>Option 3</td>
    </tr>
    <tr id="tr_0_1">
        <td>Option 1</td>
        <td>Option 2</td>
        <td>Option 3</td>
    </tr>
</table>

So after I do this:

var lTable = document.getElementById("myTable");
var trEle = lTable.insertRow(-1);
trEle.id = "tr_0_2";

var cell1 = trEle.insertCell(0);
cell1.innerHTML = "Option 1";

var cell2 = trEle.insertCell(1);
cell2.innerHTML = "Option 2";

var cell3 = trEle.insertCell(-1);
cell3.innerHTML = "Option 3";

Then I use this approach to get all of the siblings, but it NEVER gives me the last sibling in here, but ONLY if it’s been added via insertRow, because it gets all nextSiblings just fine, but once I add a sibling via insertRow it never gives me that last Sibling, argggg….

var tempTr = document.getElementById("row_0");
var totalSibs = 0;

while(tempTr.nextSibling != null)
{

    var tempId = tempTr.id;

    // If no id, not an element, or not a tr_0 id.
    if (!tempId || tempTr.nodeType != 1 || tempId.indexOf("tr_0") != 0)
    {
        tempTr = tempTr.nextSibling;
        continue;
    }

    // This NEVER ALERTS the last id of the row that was inserted using insertRow, arggg.
    alert(tempId);

    totalSibs++;

    tempTr = tempTr.nextSibling;
}

So, totalSibs should return 3 because after I inserted the row, there should be 3 Siblings, but instead returns 2 and never counts the 3rd Sibling…. arggg.

Can someone please help me here?

  • 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-05-15T00:31:24+00:00Added an answer on May 15, 2026 at 12:31 am

    The problem is at the last iteration, you set the tempTr to the next sibling, (which is actually the last tr), but you check the again the nextSibling in your while condition, in that last case it will be null, finishing the loop.

    Change your while condition to:

    while (tempTr != null) {
      //...
    }
    

    Or simply:

    while (tempTr) {
      //...
    }
    

    Try your code here.

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

Sidebar

Related Questions

I'm using SQLite & in that i'm using the following query- INSERT INTO Contact(FirstName,
Below is my simple asp code that I am using to insert some data
I need to insert a new element into an XML document using XQuery insert
Using NHibernate I need to insert an entity into a database that has a
I am trying to insert Call Logs in inbox programmatically but I am using
I have to insert 8000+ records into a SQLite database using Django's ORM. This
I need to insert more than thousand rows into an Oracle Database table every
What is the difference between using SELECT ... INTO MyTable FROM... and INSERT INTO
Problem Definiton:- I need to insert some values into Database as soon as all
How can I perform an idempotent insert row using subsonic with a SQL 2008

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.