Jquery toggleClass

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.

Example 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

Js Code

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

Html Code

<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>

Css Code

.selected-td{
	background-color: green;
	color:white;
	padding-top: 2px;
	padding-bottom: 2px;
}
Add