0

I have a pre-defined table with all rows hidden like this:

<tr id="row1" style="display: none;">
</tr>
<tr id="row2" style="display: none;">
</tr>
<tr id="row3" style="display: none;">
</tr>
<tr id="row4" style="display: none;">
</tr>
<tr id="row5" style="display: none;">
</tr>
<tr id="row6" style="display: none;">
</tr>

I am trying to use Javascript to add cells to each row and then show it. My javascript currently gets the row id and at the end it will show that row. but I can't figure out how to add cells to it, here my function:

function CreateTable(numberOfLines, linesCollection, displayCollection) {
            for (var i = 0; i < numberOfLines; i++) {
                var rowId = 'row' + (i + 1);
                var row = document.getElementById(rowId);


                document.getElementById('row' + (i + 1)).style.display = "";

          }
        }
1

1 Answer 1

2

Try this

var row = document.getElementById(rowId);
var TD = document.createElement('td'); //Create new cell
TD.innerHTML = 'This is a new cell added'; //Set some thing
row.appendChild (TD); //Add it to row
Sign up to request clarification or add additional context in comments.

1 Comment

is there a way to delete that child in a different JavaScript?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.