Skip to content
Advertisement

Hide table rows with jquery

In short I only want to show the table rows with a green ‘show’ button and I want to hide the other rows.

enter image description here screenshot 2screenshot 3

The problem is there’s a common class on the table rows because of a PHP for loop. I tried to hide the row with jQuery by using an approach that if the green button id is similar then hide other tr rows, but it doesn’t work.

Any help would be appreciated

JavaScript

The above code is just to give a class to the tr row with the green show button, but it gives a class to each tr row.

JavaScript

Advertisement

Answer

To do this you can using the :not() and :has() selectors:

JavaScript

Obviously you’ll need to amend the #yourTable and .button selectors to be relevant to the HTML in your project.

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