I use mouseover() , mouseout() and click() to highlight the lines on hover and add a selection class on click:
//Mouseover any row by adding class=mouseRow $(".mouseRow tr").mouseover(function() { $(this).addClass("ui-state-active"); }); $(".mouseRow tr").mouseout(function() { $(this).removeClass("ui-state-active"); }); $('.mouseRow tr').click(function(event) { $(this).toggleClass('selectRow'); });
The above code will allow the user to "highlight" (for example, add the selectRow class) as many lines as he wants. What is the best way to use jQuery to limit the number of rows that they can select to only one (so that by clicking one row, then clicking another, it will remove the " selectRow " class from the previously selected row)?
source share