HTML Table is not sized correctly after adding items with js
I create a table with this HTML Code:
<div class="noten_tabelle">
<table id="grades_table" style="width:100%">
<tr>
<th>Fach</th>
<th>mündlich</th>
<th>Klausur</th>
</tr>
<!-- Make content with js code -->
</table>
</div>
And in Javascript I add this things to the table. The function runs every time the server returns new loaded values. Here is the Javascript function:
function addToTable(subject, mdl, klu) {
var subject_name = getSubjectByNumber(subject);
//Zeile erstellen
var y = document.createElement([subject_name]);
y.setAttribute("id", [subject_name]);
document.getElementById("grades_table").appendChild(y);
//Spalten in einer Zeile
var cE = document.createElement("TD");
var tE = document.createTextNode([subject_name]);
cE.appendChild(tE);
document.getElementById([subject_name]).appendChild(cE);
var a = document.createElement("TD");
var b = document.createTextNode([mdl]);
a.appendChild(b);
document.getElementById([subject_name]).appendChild(a);
var c = document.createElement("TD");
var d = document.createTextNode([klu]);
c.appendChild(d);
document.getElementById([subject_name]).appendChild(c);
}
For understanding. The subject value is a number, so I turn it into a String. The result is the subject name. He is something like: "Mathematik" or "Deutsch".
I am getting this:
But that's not correct. The subject_name "Latein" is correct under the "Fach", but "5,8" should be under "mündlich". And the "11,4" should be under "klausur".
What's wrong because the "Vokalensemle should be in the next line again under "Fach", the "4,7" under "mündlich" and the empty field under "Klausur".
Oh yeah. And here is my CSS:
table {
font-family: Montserrat-Medium;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
I hope you find a solution to my Problem. If you need anything to know let me know.
javascript html css html-table
add a comment |
I create a table with this HTML Code:
<div class="noten_tabelle">
<table id="grades_table" style="width:100%">
<tr>
<th>Fach</th>
<th>mündlich</th>
<th>Klausur</th>
</tr>
<!-- Make content with js code -->
</table>
</div>
And in Javascript I add this things to the table. The function runs every time the server returns new loaded values. Here is the Javascript function:
function addToTable(subject, mdl, klu) {
var subject_name = getSubjectByNumber(subject);
//Zeile erstellen
var y = document.createElement([subject_name]);
y.setAttribute("id", [subject_name]);
document.getElementById("grades_table").appendChild(y);
//Spalten in einer Zeile
var cE = document.createElement("TD");
var tE = document.createTextNode([subject_name]);
cE.appendChild(tE);
document.getElementById([subject_name]).appendChild(cE);
var a = document.createElement("TD");
var b = document.createTextNode([mdl]);
a.appendChild(b);
document.getElementById([subject_name]).appendChild(a);
var c = document.createElement("TD");
var d = document.createTextNode([klu]);
c.appendChild(d);
document.getElementById([subject_name]).appendChild(c);
}
For understanding. The subject value is a number, so I turn it into a String. The result is the subject name. He is something like: "Mathematik" or "Deutsch".
I am getting this:
But that's not correct. The subject_name "Latein" is correct under the "Fach", but "5,8" should be under "mündlich". And the "11,4" should be under "klausur".
What's wrong because the "Vokalensemle should be in the next line again under "Fach", the "4,7" under "mündlich" and the empty field under "Klausur".
Oh yeah. And here is my CSS:
table {
font-family: Montserrat-Medium;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
I hope you find a solution to my Problem. If you need anything to know let me know.
javascript html css html-table
You are inputing only<td>
.. You didn't mind<tr>
.
– Banujan Balendrakumar
Nov 22 '18 at 17:00
add a comment |
I create a table with this HTML Code:
<div class="noten_tabelle">
<table id="grades_table" style="width:100%">
<tr>
<th>Fach</th>
<th>mündlich</th>
<th>Klausur</th>
</tr>
<!-- Make content with js code -->
</table>
</div>
And in Javascript I add this things to the table. The function runs every time the server returns new loaded values. Here is the Javascript function:
function addToTable(subject, mdl, klu) {
var subject_name = getSubjectByNumber(subject);
//Zeile erstellen
var y = document.createElement([subject_name]);
y.setAttribute("id", [subject_name]);
document.getElementById("grades_table").appendChild(y);
//Spalten in einer Zeile
var cE = document.createElement("TD");
var tE = document.createTextNode([subject_name]);
cE.appendChild(tE);
document.getElementById([subject_name]).appendChild(cE);
var a = document.createElement("TD");
var b = document.createTextNode([mdl]);
a.appendChild(b);
document.getElementById([subject_name]).appendChild(a);
var c = document.createElement("TD");
var d = document.createTextNode([klu]);
c.appendChild(d);
document.getElementById([subject_name]).appendChild(c);
}
For understanding. The subject value is a number, so I turn it into a String. The result is the subject name. He is something like: "Mathematik" or "Deutsch".
I am getting this:
But that's not correct. The subject_name "Latein" is correct under the "Fach", but "5,8" should be under "mündlich". And the "11,4" should be under "klausur".
What's wrong because the "Vokalensemle should be in the next line again under "Fach", the "4,7" under "mündlich" and the empty field under "Klausur".
Oh yeah. And here is my CSS:
table {
font-family: Montserrat-Medium;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
I hope you find a solution to my Problem. If you need anything to know let me know.
javascript html css html-table
I create a table with this HTML Code:
<div class="noten_tabelle">
<table id="grades_table" style="width:100%">
<tr>
<th>Fach</th>
<th>mündlich</th>
<th>Klausur</th>
</tr>
<!-- Make content with js code -->
</table>
</div>
And in Javascript I add this things to the table. The function runs every time the server returns new loaded values. Here is the Javascript function:
function addToTable(subject, mdl, klu) {
var subject_name = getSubjectByNumber(subject);
//Zeile erstellen
var y = document.createElement([subject_name]);
y.setAttribute("id", [subject_name]);
document.getElementById("grades_table").appendChild(y);
//Spalten in einer Zeile
var cE = document.createElement("TD");
var tE = document.createTextNode([subject_name]);
cE.appendChild(tE);
document.getElementById([subject_name]).appendChild(cE);
var a = document.createElement("TD");
var b = document.createTextNode([mdl]);
a.appendChild(b);
document.getElementById([subject_name]).appendChild(a);
var c = document.createElement("TD");
var d = document.createTextNode([klu]);
c.appendChild(d);
document.getElementById([subject_name]).appendChild(c);
}
For understanding. The subject value is a number, so I turn it into a String. The result is the subject name. He is something like: "Mathematik" or "Deutsch".
I am getting this:
But that's not correct. The subject_name "Latein" is correct under the "Fach", but "5,8" should be under "mündlich". And the "11,4" should be under "klausur".
What's wrong because the "Vokalensemle should be in the next line again under "Fach", the "4,7" under "mündlich" and the empty field under "Klausur".
Oh yeah. And here is my CSS:
table {
font-family: Montserrat-Medium;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
I hope you find a solution to my Problem. If you need anything to know let me know.
javascript html css html-table
javascript html css html-table
edited Nov 22 '18 at 19:39
Brian Tompsett - 汤莱恩
4,2031338101
4,2031338101
asked Nov 22 '18 at 16:52
marcelo.wdrbmarcelo.wdrb
859
859
You are inputing only<td>
.. You didn't mind<tr>
.
– Banujan Balendrakumar
Nov 22 '18 at 17:00
add a comment |
You are inputing only<td>
.. You didn't mind<tr>
.
– Banujan Balendrakumar
Nov 22 '18 at 17:00
You are inputing only
<td>
.. You didn't mind <tr>
.– Banujan Balendrakumar
Nov 22 '18 at 17:00
You are inputing only
<td>
.. You didn't mind <tr>
.– Banujan Balendrakumar
Nov 22 '18 at 17:00
add a comment |
2 Answers
2
active
oldest
votes
var y = document.createElement("TR");
y.setAttribute("id", [subject_name]);
//Spalten in einer Zeile
var cE = document.createElement("TD");
var tE = document.createTextNode([subject_name]);
cE.appendChild(tE);
y.appendChild(cE);
var a = document.createElement("TD");
var b = document.createTextNode([mdl]);
a.appendChild(b);
y.appendChild(a);
var c = document.createElement("TD");
var d = document.createTextNode([klu]);
c.appendChild(d);
y.appendChild(c);
document.getElementById("grades_table").appendChild(y);
add a comment |
I couldn't see in your code where you are adding the new parent table row for your new table cells.
The cells will align if they are within a new row, with the same number of table cells.
Append a new tr
and add the new td
cells to that.
If you need to have uneven number of cells per row, you will need to use colspan={number of columns cell will span over}
.
Would you like a code example?
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435404%2fhtml-table-is-not-sized-correctly-after-adding-items-with-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
var y = document.createElement("TR");
y.setAttribute("id", [subject_name]);
//Spalten in einer Zeile
var cE = document.createElement("TD");
var tE = document.createTextNode([subject_name]);
cE.appendChild(tE);
y.appendChild(cE);
var a = document.createElement("TD");
var b = document.createTextNode([mdl]);
a.appendChild(b);
y.appendChild(a);
var c = document.createElement("TD");
var d = document.createTextNode([klu]);
c.appendChild(d);
y.appendChild(c);
document.getElementById("grades_table").appendChild(y);
add a comment |
var y = document.createElement("TR");
y.setAttribute("id", [subject_name]);
//Spalten in einer Zeile
var cE = document.createElement("TD");
var tE = document.createTextNode([subject_name]);
cE.appendChild(tE);
y.appendChild(cE);
var a = document.createElement("TD");
var b = document.createTextNode([mdl]);
a.appendChild(b);
y.appendChild(a);
var c = document.createElement("TD");
var d = document.createTextNode([klu]);
c.appendChild(d);
y.appendChild(c);
document.getElementById("grades_table").appendChild(y);
add a comment |
var y = document.createElement("TR");
y.setAttribute("id", [subject_name]);
//Spalten in einer Zeile
var cE = document.createElement("TD");
var tE = document.createTextNode([subject_name]);
cE.appendChild(tE);
y.appendChild(cE);
var a = document.createElement("TD");
var b = document.createTextNode([mdl]);
a.appendChild(b);
y.appendChild(a);
var c = document.createElement("TD");
var d = document.createTextNode([klu]);
c.appendChild(d);
y.appendChild(c);
document.getElementById("grades_table").appendChild(y);
var y = document.createElement("TR");
y.setAttribute("id", [subject_name]);
//Spalten in einer Zeile
var cE = document.createElement("TD");
var tE = document.createTextNode([subject_name]);
cE.appendChild(tE);
y.appendChild(cE);
var a = document.createElement("TD");
var b = document.createTextNode([mdl]);
a.appendChild(b);
y.appendChild(a);
var c = document.createElement("TD");
var d = document.createTextNode([klu]);
c.appendChild(d);
y.appendChild(c);
document.getElementById("grades_table").appendChild(y);
answered Nov 22 '18 at 17:03
Banujan BalendrakumarBanujan Balendrakumar
8391212
8391212
add a comment |
add a comment |
I couldn't see in your code where you are adding the new parent table row for your new table cells.
The cells will align if they are within a new row, with the same number of table cells.
Append a new tr
and add the new td
cells to that.
If you need to have uneven number of cells per row, you will need to use colspan={number of columns cell will span over}
.
Would you like a code example?
add a comment |
I couldn't see in your code where you are adding the new parent table row for your new table cells.
The cells will align if they are within a new row, with the same number of table cells.
Append a new tr
and add the new td
cells to that.
If you need to have uneven number of cells per row, you will need to use colspan={number of columns cell will span over}
.
Would you like a code example?
add a comment |
I couldn't see in your code where you are adding the new parent table row for your new table cells.
The cells will align if they are within a new row, with the same number of table cells.
Append a new tr
and add the new td
cells to that.
If you need to have uneven number of cells per row, you will need to use colspan={number of columns cell will span over}
.
Would you like a code example?
I couldn't see in your code where you are adding the new parent table row for your new table cells.
The cells will align if they are within a new row, with the same number of table cells.
Append a new tr
and add the new td
cells to that.
If you need to have uneven number of cells per row, you will need to use colspan={number of columns cell will span over}
.
Would you like a code example?
answered Nov 22 '18 at 17:00
BenHerbertBenHerbert
14029
14029
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435404%2fhtml-table-is-not-sized-correctly-after-adding-items-with-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You are inputing only
<td>
.. You didn't mind<tr>
.– Banujan Balendrakumar
Nov 22 '18 at 17:00