Skip to content
Advertisement

Hide and show rows in a table

I intend to have a table that initially shows the existing budgets. Then if you want to see the content of the budget then I click the button in the first column and it shows what belongs to each budget. I’m doing this as I show in the example below:

JavaScript
JavaScript

The problem I have is that when I click the button in the first column to see the contents of budget 1, it shows the information for budget 1 and budget 2.

I intend that when clicking on the budget 1 button, show me only the lines that belong to budget 1 and so on.

can someone help with the example I put above or else suggested something different but with the same functionality?

Advertisement

Answer

The problem here is in your loop which iterates over cars1‘s keys:

JavaScript

In this loop you iterates over all the keys in cars1 object and for each one of them you create a row in the table.

To reach your goal, instead, you should intercept user’s click on the button and then display a single row with the details of that budget.

You can use data- attributes to know which budget user has clicked.

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