Having an html code like this:
<table>
<tr>
<td bgcolor=yellow>LED #1</td>
<td id=led0 bgcolor=red>ON</td>
</tr>
<tr>
<td bgcolor=yellow>LED #2</td>
<td id=led1 bgcolor=red>ON</td>
</tr>
<tr>
<td bgcolor=yellow>LED #3</td>
<td id=led2 bgcolor=red>ON</td>
</tr>
<tr>
<td bgcolor=yellow>LED #4</td>
<td id=led3 bgcolor=red>ON</td>
</tr>
<tr>
<td>
<button>number 1</button>
</td>
</tr>
<tr>
<td>
<button>number 2</button>
</td>
</tr>
<tr>
<td>
<button>number 3</button>
</td>
</tr>
</table>
I would like to achieve something like this:
$('button').click(function() {
var index = $("button").index(this);
// alert(index);
$("#led[index]").html('<div style="background:#cccccc" >OFF</div>');
});
In words: I want to detect the button pressed (which is already working) and then modify the html code of the td element with id="led[index]" and using the variable "index" to find the right led number.
Any idea?