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

  • Home
  • SEARCH
  • 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 767415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:01:27+00:00 2026-05-14T18:01:27+00:00

I have a situation when there’s a table and you can add a new

  • 0

I have a situation when there’s a table and you can add a new row by clicking a button. The row is dynamically generated by a server and it is passed back in HTML. So basically what i need to do is prefix the new row to the old table. Something like this:

tableelement.innerHTML = newHtml + tableelement.innerHTML;

That surely works, but i have a table header and, obviously, i need to insert the new html after it. How would i do this? insertBefore or insertAfter can’t help (afaik), because they’re meant for inserting elements and not unparsed HTML. So how could i, having an object of the header’s row, insert another row (in HTML) after it (or before) ?

Thank you for your ideas

  • 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-14T18:01:27+00:00Added an answer on May 14, 2026 at 6:01 pm

    I would consider rethinking the approach. innerHTML is read-only for tables in Internet Explorer, so you’re bound to run into interoperability issues with your current method. You could restructure your code to build the elements using the DOM instead of specifying the innerHTML. It’s fairly straightforward, much more efficient (doesn’t invoke the parser) and more cross-browser compatible.

    Mozilla seems to agree with Microsoft on this, and to quote the element.innerHTML documentation:

    [innerHTML] should never be used to write parts of a table—W3C DOM methods should be used for that—though it can be used to write an entire table or the contents of a cell.

    The process involves using the DOM Level 2 methods, table.insertRow() and tr.insertCell(). For a decent read, see Building Tables Dynamically (MSDN).

    Example (from MDC):

    function addRow(tableID)
    {
      // Get a reference to the table
      var tableRef = document.getElementById(tableID);
    
      // Insert a row in the table at row index 0
      var newRow   = tableRef.insertRow(0);
    
      // Insert a cell in the row at index 0
      var newCell  = newRow.insertCell(0);
    
      // Append a text node to the cell
      var newText  = document.createTextNode('New top row')
      newCell.appendChild(newText);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following situation: there is a table in the DB that is
I have the following situation: There is a tool that gets an XSLT from
I have this situation: There are a login page with a login form (form
I have such situation: There is 8 div-blocks with ids like 'rateN_wrapper' where is
I have a situation where there is a selectOneMenu that has a value bound
I have a situation where there is a small piece of Java code that
I have a situation where there is a corrupt WAV file from which I'm
I have the following situation: There is a windows folder that has been mounted
I have a situation where there is a rule with a shift/reduce conflict that
I have the following situation: There is one custom view inside of the first

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.