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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:56:06+00:00 2026-05-19T14:56:06+00:00

I have a table as follows: <table> <tr> <td>col 1</td><td>col2</td> </tr> <tr id=insert> <td>field</td><td>Field

  • 0

I have a table as follows:

<table>
 <tr>
   <td>col 1</td><td>col2</td>
 </tr>
 <tr id="insert">
   <td>field</td><td>Field 2</td>
 </tr>
 <tr>
   <td>another field</td><td>one more field</td>
 </tr>
</table>

Now the issue is that I need to dynamically insert new rows AFTER the middle row (id = insert). I have a custom javascript function to insert elementsAFTER an element by using an insertBefore call on the next element.

The new rows create successfully using the following javascript:

var new_row = document.createElement('tr');
new_row.innerHTML="<td>test</td>";
insertAfter(document.getElementById("insert"), new_row);

However, the new row refuses to accept any simple html formatting using the innerHTML. The final output of the new row looks something like:

<tr>test</tr>

You see it doesn’t want to output the I have specified. The actual script is a lot more complex and so unfortunately manually adding each using an appendChild or similar function would be far too time consuming and probably rather resource intensive. Is there anyway I can just add a ‘chunk of html’ to this table row and in this chunk define the table columns?

I’m baffled, any help is MUCH appreciated.

  • 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-19T14:56:07+00:00Added an answer on May 19, 2026 at 2:56 pm

    You can use the native insertCell() method to insert cells.

    Give this a try:

    Example: http://jsfiddle.net/VzTJa/

    var new_row = document.createElement('tr');
    new_row.insertCell(0).innerHTML = "test";
    new_row.insertCell(1).innerHTML = "test2";
    

    or you can accomplish it without your insertAfter() function by using insertRow() as well.

    Example: http://jsfiddle.net/VzTJa/1/

    var insert = document.getElementById("insert");
    var new_row = insert.parentNode.insertRow( insert.rowIndex + 1 );
    new_row.insertCell(0).innerHTML = "test";
    new_row.insertCell(1).innerHTML = "test2";
    

    Give this workaround a try:

    Example: http://jsfiddle.net/VzTJa/2/

    var temp = '<table><tbody><tr>';
    var close_temp = '</tr></tbody></table>';
    var temp_div = document.createElement('div');
    
    
    var html_to_insert = '<td>tester</td><td>tester</td>';
    
    temp_div.innerHTML = temp + html_to_insert + close_temp;
    insertAfter(document.getElementById("insert"), temp_div.firstChild.firstChild.firstChild);
    
    temp_div.removeChild(temp_div.firstChild);
    

    Basically creates a couple strings representing the opening and closing tags of a table. You concatenate it with your content, and set it as the innerHTMl of a temporary div, then fetch the row you want, and do an .appendChild().

    There may be a better way, or you may find a way to improve this one.

    I came up with this after glancing at a solution in this article from a guy who apparently worked on IE and is partly responsible for the parser.

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

Sidebar

Related Questions

I have a table as follows; <table> <tr> <th scope=col></th> <th scope=col>Column One</th> <th
I have table of data that is sorted as follows: Item | Sample |
I have a table as follows col1 col2 col3 a 01/01/2001 1.1 a 01/02/2001
I have a table that displays months(Jan through Dec) in a table as follows.
I have several databases that each have a table called, say, products . One
I have a table as follows. I need to give background color(yellow) only to
Suppose I have a table as follows: (on DB2 9.7.2) COL1 COL2 COL3 -----------
Fellow Query Writers, I have a table as follows: myTable t1 col2 col3 2
I have a table that holds allocations of problem reports (PRs) as follows: TABLE
I have a table that represents a series of matches between ids from another

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.