String selection in Tablesorter

I am a user of the Tablesorter jQuery plugin (I'm sure others know about it) in my project. I need to add a function in which, when users click on a line, it is selected. I tried the following code but did not work.

$('#myTable tr').click(function(event) {
     $(this).addClass('selected');

 });

Can someone tell me the best way to do this? Is there a plugin for this?

Thanks in advance,
Abdel Olakar

+3
source share
5 answers

, Tablesorter , , , "" click, tr. , : jQuery.com

0

jQuery toggleClass:

$(document).ready( function() {
    /* jQuery v1.11.1 */
    $( "table.tablesorter tbody tr" ).click(function() {
      $( this ).toggleClass( "selected" );
    });
});

/* CSS for hover row & select/lock the row with color */
table.tablesorter tbody tr:hover td {
    background-color: #f4f5f6;
}
table.tablesorter tbody tr.selected td {
    background-color: #f4f5f6;
}
+4

. CSS, tr.selected?

, , td, tr. , :

http://docs.jquery.com/Traversing/parent

- (untested):

$('#myTable td').click(function(event) {
         $(this).parent("tr").addClass('selected');

 });
+1

, , . , ?

$(function() {
    $('#myTable tr').click(function() {
         $(this).addClass('selected');
    });
});

Alternatively, you can use liveevents.

$('#myTable tr').live('click', function() {
     $(this).addClass('selected');
});
+1
source

Your click event seems to work fine on my table, I'm just wondering how you deselect by clicking again? binding a variable to whether it is selected seems like a simple solution, but how would I do it?

Forgive me for answering your question with another question and my novelty for JS.

0
source

Source: https://habr.com/ru/post/1719513/


All Articles