My task is to make a page with a table and a button. When the user presses a button, one row is added to the table.
So, I have a button on my html page ( <button id="my_button">Bla-bla</button> ),
and a table ( <table id="my_table"> ). And I have a separate file for JavaScript. In that file I wrote:
$(function() {
$(my_button).click(function(){
tbl = document.getElementById("my_table");
row = tbl.insertRow(0);
var newCell = row.insertCell(0);
newCell.height=300;
newCell.innerHTML="Some New Text";
});
});
But there is a problem: when I press the button, the row is added for several milliseconds, then it vanishes and I see the table without the new row again. What is the problem and how can I solve it?
setTimeoutor the like?$('#my_table')and$('#my_table').append()?formwhen you click the button, so the page refreshes.