How to create a table via dom js?
-
https://jsfiddle.net/56crvoxh/1/
Hello everyone, please tell me when you click on edit = & gt; add = & gt; table there are 2 types of tables list, table
list, when you click on save, everything is created correctly without problems, and table creates an incorrect table.
In the comments I will leave a photo of how it creates 2x2JavaScript Anonymous, Jul 7, 2019 -
In tr () and td () you create a new table each time, not a row / column.
function tr(){
texta.value += '<table><tbody>'; // Один раз создаёте таблицу
for(let i = 0; i<table1.value;i++){
texta.value += '<tr>';
td(); /* Вызов td() должен быть тут, внутри строки, и нигде больше */
texta.value += '</tr>';
// texta.value += `<table><tbody><tr><td style = "width:${table4.value}px;height:${table3.value}px;border:${table5.value}px ${tableselect.value} ${colorselect.value}"</td></tr>`
}
}
function td(){
for(let i = 0; i<table2.value;i++){
texta.value += '<td style = "width:${table4.value}px;height:${table3.value}px;border:${table5.value}px ${tableselect.value} ${colorselect.value}"</td>';
// texta.value += `<table><tbody><tr><td style = "width:${table4.value}px;height:${table3.value}px;border:${table5.value}px ${tableselect.value} ${colorselect.value}"</td></tr>`
}
}Anonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!