After loading several images onto the page, I hide them using 'display:none':
<div id="cont-img">
<img class="lista-img" src="list/1.png" id="v1" />
<img class="lista-img" src="list/2.png" id="v2" />
<img class="lista-img" src="list/3.png" id="v3" />
<img class="lista-img" src="list/4.png" id="v4" />
<img class="lista-img" src="list/5.png" id="v5" />
<img class="lista-img" src="list/6.png" id="v6" />
<img class="lista-img" src="list/7.png" id="v7" />
<img class="lista-img" src="list/8.png" id="v8" />
<img class="lista-img" src="list/9.png" id="v9" />
<img class="lista-img" src="list/10.png" id="v10" />
<img class="lista-img" src="list/11.png" id="v11" />
<img class="lista-img" src="list/12.png" id="v12" />
<img class="lista-img" src="list/13.png" id="v13" />
</div>
Next, I decide to display 8 of these images in a table:
<table align="center">
<tr id="riga-img">
<td class="td-img" id="iv1"></td>
<td class="td-img" id="iv2"></td>
<td class="td-img" id="iv3"></td>
<td class="td-img" id="iv4"></td>
<td class="td-img" id="iv5"></td>
<td class="td-img" id="iv6"></td>
<td class="td-img" id="iv7"></td>
<td class="td-img" id="iv8"></td>
</tr>
</table>
I want to retrieve the ID of the image within a specific table cell when it is clicked. So, I try this jQuery code:
$("#riga-img td").click(function(){
var id=$(this).child().attr('id');
Unfortunately, this code does not work as expected.