Nov 18, 2022

# Solution 1 :

One possible solution, kudos to this answer: @Neil:

``````\$("#datosTabla").find('tbody')
.append(\$('<tr>')
.append(\$('<td>')
.append(\${formatoFecha(fechaX)})
)
//etc...
);
``````

# Solution 2 :

Consider the following.

``````\$.each(plazos, function(k, v) {
pagosIntereses = parseFloat(valor * (tasas / 100));
pagoAmortizacion = pagoMensual - pagosIntereses;
valor = parseFloat(valor - pagoAmortizacion);
fechaX = hoy.setMonth(hoy.getMonth() + 1);
//creacion de las filas
var fila = \$("<tr>").appendTo(datosTabla);
\$("<td>").html(formatoFecha(fechaX)).appendTo(fila);
\$("<td>", {
class: "valorCuota"
}).html(pagoMensual.toFixed(2)).appendTo(fila);
\$("<td>").html(pagoAmortizacion.toFixed(2)).appendTo(fila);
\$("<td>").html(pagosIntereses.toFixed(2)).appendTo(fila);
\$("<td>").html(valor.toFixed(2)).appendTo(fila);
});
``````

This performs the same Loop yet appends a new Row and then appends new Cells to that Row.

See More:

# Solution 3 :

I appreciate all of your responses! They have helped me to reach this solution.

``````\$("#tablaBody").append(`<tr><td>\${formatoFecha(fechaX)}
<td class="valorCuota">\${pagoMensual.toFixed(2)}</td>
<td>\${pagoAmortizacion.toFixed(2)}</td>
<td>\${pagosIntereses.toFixed(2)}</td>
<td>\${valor.toFixed(2)}</td>`);
``````

I thank you very much

# Problem :

everything was going well until I had two problems with jquery, and this is the second.

I have this javascript code, inside a function, that creates “tr” elements and then through a for it adds them to a table already created in html.

``````for(let i = 1; i <= plazos; i++) {

pagosIntereses = parseFloat(valor*(tasas/100));
pagoAmortizacion = pagoMensual - pagosIntereses;
valor = parseFloat(valor-pagoAmortizacion);

fechaX = hoy.setMonth(hoy.getMonth() + 1);
//creacion de las filas
const fila = document.createElement("tr");
fila.innerHTML =
`   <td>\${formatoFecha(fechaX)}
<td class="valorCuota">\${pagoMensual.toFixed(2)}</td>
<td>\${pagoAmortizacion.toFixed(2)}</td>
<td>\${pagosIntereses.toFixed(2)}</td>
<td>\${valor.toFixed(2)}</td>`;
datosTabla.appendChild(fila);
}
``````

Now I try to pass it to Jquery and I can’t make it work, I tried to do the following which was what I logically came up with, but I couldn’t

``````    const fila = \$("tr").append(
`<td>\${formatoFecha(fechaX)}
<td class="valorCuota">\${pagoMensual.toFixed(2)}</td>
<td>\${pagoAmortizacion.toFixed(2)}</td>
<td>\${pagosIntereses.toFixed(2)}</td>
<td>\${valor.toFixed(2)}</td>`);
datosTabla.appendChild(fila);
``````

### Comment posted by stackoverflow.com/a/1278557/8104777

Try out this solution:

### Comment posted by Twisty

Your selector is too widely scoped.

### Comment posted by Twisty

If you are trying to create a new element, this is done with