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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:38:41+00:00 2026-05-24T03:38:41+00:00

I am just learning this stuff so please forgive if my code or questions

  • 0

I am just learning this stuff so please forgive if my code or questions are very basic.

My “working code” (no errors etc) just so you know what I have so far:

var t = document.createElement("table"),
    tr = document.createElement("tr"),
    tr2 = document.createElement("tr"),
    td = document.createElement("td"),
    td2 = document.createElement("td"),
    a = document.createElement("a"),
    strong = document.createElement("strong");

t.style.width = "80%";
t.style.border = "0";
t.cellspacing = "2";
t.cellpadding = "2";

.

for (var i = 0; i < nodes.length; i++) {
    the_table_color = nodes[i].getAttribute("table_color");
    the_type = nodes[i].getAttribute("type");
    alt_link = nodes[i].getAttribute("alt_link");
    link_for_deletion = nodes[i].getAttribute("link_for_deletion");
    comment = nodes[i].getAttribute("comment");

    tr.bgColor = the_table_color;
    t.appendChild(tr);

    td.width = "16%";
    td.vAlign = "top";
    tr.appendChild(td);

    strong.appendChild(document.createTextNode(the_type));
    td.appendChild(strong);

    td.width = "16%";
    td.vAlign = "top";
    tr.appendChild(td);

    td2.width = "70%";
    td2.vAlign = "top";
    tr.appendChild(td2);

    a.href = alt_link;
    a.appendChild(document.createTextNode(alt_link));
    a.target = "_blank";
    td2.appendChild(a);
}

As you can see from above I have this bit:

td = document.createElement("td"),
    td2 = document.createElement("td"),

and the reason for that is, if I do not have the “td” declared again, the first one gets overwritten and the second one does not display…
A) Is that the right way of doing this? (not sure if this is the right approach,I came about the solution of declaring another variable to get it to work, but it seems like extra code)

Then this line of code:

strong.appendChild(document.createTextNode(the_type));

just adds all the stuff from the loop in there 🙁
For example of the first iteration of the for() loop has abc and the second had def it displays abcdef instead of abc the first time and def the second.
B) Why is that and how do I fix it?

Thanks!

  • 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-24T03:38:42+00:00Added an answer on May 24, 2026 at 3:38 am

    Your for loop is executing against the same instance with each iteration. You will not get multiple rows of data unless you perform your:

    document.createElement("TR");
    document.createElement("TD");
    

    within the loop body. Otherwise, you’re exactly right, you’re just appending the same text to the same row and table cell each iteration through the loop.

    It sounds like you need to change your approach to something like:

    var table = document.createElement("TABLE");
    for(var i = 0; i < nodes.length; i++){
        var tr = document.createElement("TR");
        var td = document.createElement("TD");
        tr.appendChild(td);
        table.appendChild(tr);
    
        // do something to to td    
    }
    

    Let me know if I’ve misunderstood your question, but if you’re wondering why your table is building only one row or repeatedly modifying the same cell, that’s definitely why… if there’s more to your question let me know and I’ll update the posting.

    Happy coding.

    B

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

Sidebar

Related Questions

Just to clarify while learning this stuff: If I have a scene with just
I'm guessing this is a simple problem, but I'm just learning... I have this:
I just started learning C but I don't understand this part of the code.
I am new to Scala, just started learning, so this is basic beginner question.
I am just learning how to make basic stuff with a WebMatrix download, with
Just learning this stuff, so bear with any ignorance... In what I'm trying to
I'm just learning MongoDB and MongoMapper. This is on Rails 3. I created a
I was just reading through Learning Python by Mark Lutz and came across this
I'm learning about POSIX threads right now, but I guess this is just a
Im just learning mod_rewrite and regex stuff, and what I'm trying to do is

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.