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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:39:15+00:00 2026-06-18T11:39:15+00:00

I have an object with some address information in it that I would like

  • 0

I have an object with some address information in it that I would like to append() to an HTML table.

The table starts like this:

<table class="shipping_information" border="1">

</table>

And then I put my address information into another table (line 5 here), and put that table into a <td>. I’m trying to make it so that there is a maximum number of <td>s (here 2). If it is over 2, a new <tr> will be appended.

function add_shipping_address_to_shipping_container(address_obj, shipping_container) {
    var append_to_table = "";
    var table = shipping_container.find('table.shipping_information');
    var max_td = 2;
    var formatted_address = format_address(address_obj); //returns a table with the address

    //are there any rows in the table
    var is_tr = table.find('tr.shipping_address_container_table').length;
    if (!is_tr) {
        //no tr so append tr and td
        //colspan should be max_td
        append_to_table = "<tr class='add_container'><td class='add_container'>" + formatted_address +"</td></tr>"
    } else {
        //there is a tr
        var last_tr = table.find('tr.add_container:last');
        //number of tds in the last row
        var num_td = last_tr.find('td.add_container').length;
        if (num_td >= max_td) {
            append_to_table = "<tr class='add_container'><td class='add_container'>" + formatted_address + "</td></tr>";
        } else {
            append_to_table = "<td class='add_container'>" + formatted_address + "</td>";
        }

    }
    table.append(append_to_table);
}

However, the <td>s aren’t appending as I would imagine. It makes a new <tr> each time. when I print the variable append_to_table to the console, it looks right. <tr><td></td></tr> when there should be, and just <td></td> when that should be the case. Is jquery or chrome automatically appending a new <tbody> each time or something?

jsbin

  • 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-18T11:39:16+00:00Added an answer on June 18, 2026 at 11:39 am

    When you are checking for a new row, you are searching for a class shipping_address_container_table but when you are creating the new row. You are only adding a tr with class add_container.

    Your current code isn’t doing anything except the first portion (!is_tr always == true). That’s probably your problem.

    Also, I moved the append for existing tr elements to the tr instead of the table to make sure jquery doesn’t automatically wrap the td in a new tr.

    This worked for me:

    function add_shipping_address_to_shipping_container(address_obj, shipping_container) {
        var append_to_table = "";
        var table = shipping_container.find('table.shipping_information');
        var max_td = 2;
        var formatted_address = format_address(address_obj); //returns a table with the address
        //are there any rows in the table
        var is_tr = table.find('tr.add_container').length;
        if (!is_tr) {
            //no tr so append tr and td
            //colspan should be max_td
            append_to_table = "<tr class='add_container'><td class='add_container'>" + formatted_address + "</td></tr>";
        table.append(append_to_table);
        } else {
            //there is a tr
            var last_tr = table.find('tr.add_container:last');
            //number of tds in the last row
            var num_td = last_tr.find('td.add_container').length;
            if (num_td >= max_td) {
                append_to_table = "<tr class='add_container'><td class='add_container'>" + formatted_address + "</td></tr>";
        table.append(append_to_table);
            } else {
                append_to_table = "<td class='add_container'>" + formatted_address + "</td>";
        last_tr.append(append_to_table);
            }
    
        }
    }
    
    function format_address(address_obj){
    
        var address_table = "<table border='1'>";
    
        address_table += ("<tr><td class='shipping_address_table'>" + address_obj.attn + "</td></tr>");
        address_table += ("<tr><td class='shipping_address_table'>" + address_obj.company_name + "</td></tr>");
        address_table += ("<tr><td class='shipping_address_table'>" + address_obj.address_1 + "</td></tr>");
    
        address_table += "</table>";
    
        return address_table;
    }
    
    $(document).ready(function(){
      $('body').on('click', '#button', function(){
      var address_obj = {
        attn : "sample attention",
        company_name : "sample company",
        address_1 : "sample line 1"
      },
      shipping_container = $('#wrapper');
    
      add_shipping_address_to_shipping_container(address_obj, shipping_container);
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object of some class that obeys the singleton pattern. I need
Ok, let's imagine I have an object like this: public class User { public
I have some object that's been added to the body of my page via
I have some object that is instantiated in code behind, for instance, the XAML
I think I read somewhere that some modules only have object oriented interfaces (
I have an object called Layer that has some attributes and some methodes. i
I need to have some object hanging around between two events I'm interested in:
I have a data() object containing some json. Is there a way I can
My current setup : I have an entity object with some properties, among them
i have resultset object and it containing some country names. e.g. rs={India, Japan, USA,

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.