We are learn about Jquery toggleClass function. Usign this function you can add or remove class. if class is added then it's remove and not added then add class. this is use for select and deselect.
nicesnippets.com provide best example to how to implement toggleClass function. and also provide source code with demo.
nicesnippets.com For Snippets |
nicesnippets.com For Tutorials |
nicesnippets.com For Live Demo |
nicesnippets.com For Live HTML Editor |
nicesnippets.com For Live HTML Editor |
nicesnippets.com For Online Counter |
$('table tr').click(function() {
$(this).toggleClass("selected-td");
});
<table class="table">
<tbody>
<tr>
<td>nicesnippets.com For Snippets</td>
</tr>
<tr>
<td>nicesnippets.com For Tutorials</td>
</tr>
<tr>
<td>nicesnippets.com For Live Demo</td>
</tr>
<tr>
<td>nicesnippets.com For Live HTML Editor</td>
</tr>
<tr>
<td>nicesnippets.com For Live HTML Editor</td>
</tr>
<tr>
<td>nicesnippets.com For Online Counter</td>
</tr>
</tbody>
</table>
.selected-td{
background-color: green;
color:white;
padding-top: 2px;
padding-bottom: 2px;
}