I'm trying to get it so table cells within a row that are clicked on changes the background colour.
HTML code:
<table border="1" cellpadding="10">
<tbody>
<tr>
<td>Hello World</td>
<td>Hello World 2</td>
</tr>
<tr>
<td>Hello World</td>
<td>Hello World 2</td>
</tr>
<tr>
<td>Hello World</td>
<td>Hello World 2</td>
</tr>
</tbody>
</table>
Script code:
$( function() {
$('td').click( function() {
$(this).parents('table').find('td').each( function( index, element ) {
$(element).removeClass('on');
} );
$(this).addClass('on');
} );
} );
The stylesheet has a .on class that changes the background colour when clicked.
It's working fine at the moment, but I'm trying to get it where multiple cells can be clicked and background changed, but only one cell per row.
I figure I need some classes within the tr/td tags in the table but not entirely sure the script code to work it, googled quite a few different things but not come across anything yet.
Any ideas appreciated.