I am working on the table of HTML with jquery, highlight the row when selected and double click to remove highlight as well as only one selected at the time.

Below code, can only be achieved one goal which is only one selected at a time.

$("#tableRecord tr").click(function(){
        $(this).addClass("clicked").siblings().removeClass("clicked");
    });

In the table, I want only one selected at a time and a selected item can be de-selected when clicked on it again.

1 Answers

1
delinear On Best Solutions

You can use jQuery's hasClass() method to check if the link has already been clicked and then deselect it, or if it hasn't been clicked, then select it and deselect all others:

$("#tableRecord tr").click(function(){
  if ($(this).hasClass("clicked")) {
    $(this).removeClass("clicked");
  } else {
    $(this).addClass("clicked").siblings().removeClass("clicked");
  }
});