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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:07:54+00:00 2026-06-09T13:07:54+00:00

I am trying to add a table row dynamically via jQuery. Everything works fine

  • 0

I am trying to add a table row dynamically via jQuery. Everything works fine but the row just won’t add itself to the last < tr>. Instead, it adds itself above the < table>…

I am quite confused. Could anyone help me out? Here is the code

Javascript

var counterx = 2;
var counter = 2;

$(document).ready(function(){
    $("#addMoreRcpt").click(function(){
        if (counterx>10){
            alert("Only 10 reciepients are allowed");
            return false;
        }

        var newTextBoxDiv = $(document.createElement('div')).attr("id", 'RcptEml_' + counter);
        newTextBoxDiv.append("<tr><td>New Data</td><td>New Data</td><td>New Data</td></tr>");

        newTextBoxDiv.appendTo("#RcptGroup");
        counter++;
        counterx++;
    });
});

function fncDelRcpt(id){
    $("#RcptEml_"+id).remove();
    counterx--;
}

HTML

<table border=1>
<div id="RcptGroup">
<tr>
    <th>1</th>
    <th>2</th>
    <th>3</th>
</tr>
<div id="1">
<tr>
    <td>data</td>
    <td>Data</td>
    <td>data</td>
</tr>
</div>
</div>

</table>
<br /><a id="addMoreRcpt" href="#" >Add more reciepients</a>
  • 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-09T13:07:55+00:00Added an answer on June 9, 2026 at 1:07 pm

    Here’s changed parts of your code that should work:

    The Script:

    $(document).ready(function() {
        $("#addMoreRcpt").click(function() {
            if (counterx > 10) {
                alert("Only 10 reciepients are allowed");
                return false;
            }
            var newTextBoxRow = $(document.createElement('tr')).attr("id", 'RcptEml_' + counter);
            newTextBoxRow.append("<td>New Data</td><td>New Data</td><td>New Data</td>");
            newTextBoxRow.appendTo("#RcptGroup");
            counter++;
            counterx++;
        });
    });​
    

    The Table:

    <table border="1" id="RcptGroup">
        <tr id="0">
            <th>1</th>
            <th>2</th>
            <th>3</th>
        </tr>
        <tr id="RcptEml_1">
            <td>data</td>
            <td>Data</td>
            <td>data</td>
        </tr>
    </table>​​​​​​​​​​​​
    

    Working fiddle: http://jsfiddle.net/pratik136/2au73/5/


    As suggested in the comments to your question, <Div/>s cannot be nested within <Table/>s. Here’s a guideline for HTML 4.01, but almost all of it should still hold true: http://www.cs.tut.fi/~jkorpela/html/nesting.html

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

Sidebar

Related Questions

I'm trying to add a table row with ajax/jquery that has a form element
I am trying to add a table row to a table using .after() but
I'm trying to insert some dynamically generated html (via PHP) into a table, but
I am trying to add table row dynamically in my activity. The table row
I'm trying to add a row dynamically to a tablesorter table with a pager.
I am trying to add style to a table row in C# code. However,
I'm just trying to add 2 columns to customer table alter table CUSTOMER ADD
I´m trying to add a list to a table cell but there are no
i'm trying to add a foreign key to my table, but when i try
I am trying to add a border and padding to the table row of

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.