I have a table with several rows. On each line there is a button "Show details" and a button "Hide information". When I click on the "Show Details" button, I want the "Hide Details" button to be displayed only for a specific line. I thought the .closest () function would work, but that's not all.
Here is the HTML
<table> <tr id="1"> <td><button class='view'>View Details</button><button class='hide' style='display:none;'>Hide Details</button></td> </tr> <tr id="2"> <td><button class='view'>View Details</button><button class='hide' style='display:none;'>Hide Details</button></td> </tr> </table>
Here is jQuery
$(".view").click(function() { $("#patient").show(""); $(this).hide(); $(this).closest(".hide").show(); });
source share