简体   繁体   中英

Toggle class on each tr row when clicked

For some reason I can't get the class of "selected" to toggle on when each row is clicked

Example: http://jsfiddle.net/g8gumhg0/1/

jQuery:

$("tr").click(function() {
      $(this).toggleClass('selected');
};

CSS:

table tr.user:hover {
    background: #007A00;
}
table tr.selected {
    background: #198719;
}

Should be a simple fix, but I can't see what I'm doing wrong.

$("tr").click(function() {
      $(this).toggleClass('selected');
});

You are missing a closing bracket at the end.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM