surajR
surajR

Reputation: 573

how to toggle table rows using jquery with one row toggling at one time?

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

Answers (2)

thecodeparadox
thecodeparadox

Reputation: 87073

I assume a click event

$('table tr').on('click', function() {
  $('table tr:visible').hide();
  $(this).toggle();
})

Upvotes: 1

Mathew Thompson
Mathew Thompson

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

Related Questions