Skip to content
Advertisement

How can I use JavaScript to delete a row in an HTML table and its associated data when a button is clicked?

How can I use JavaScript to delete a row in an HTML table and its associated data when a button is clicked? What is the most efficient way to identify the row to be deleted, and what method should I use to remove the row from the DOM? Additionally, how can I ensure that the deletion of the row does not affect the styling or functionality of the remaining rows in the table?

When I click on the button: Remover, the line is hidden. When I click the Adicionar button again, the line that was hidden is added. I want the line along with the data to be definitively deleted when I click on the button: Remover.

I’ve tried using several methods and I can’t solve it, can anyone help?

JavaScript
JavaScript
JavaScript

Advertisement

Answer

The issues is you are storing the all the generated html in linhas which is a string and when deleting you never removed the from this variable. I have converted this to array so that we can delete the row.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement