Reputation: 573
I have created an html table which have toggle rows.But what i want is when i toggle one row previously toggled row should hide. pls help
Upvotes: 1
Views: 1723
Reputation: 87073
I assume a click event
$('table tr').on('click', function() {
$('table tr:visible').hide();
$(this).toggle();
})
Upvotes: 1
Reputation: 56429
What about this? Assuming you're doing this on click that is, then you can stored the last clicked item into a variable. Like so:
var lastClicked;
$("#yourTable tr").on("click", function () {
if (lastClicked != null) {
lastClicked.hide();
}
$(this).toggle();
lastClicked = $(this);
});
Upvotes: 0