hi to all,
i have a list of records with link with each record
i have like this table structure
<table>
<tr>
<td>ID</td>
<td>Name</td>
<td>Image</td>
</tr>
after that dynamic tr and td are created which list the name of cateogy and its image
<tr>
<td>1</td>
<td>cat1</td>
<td><a id=“1” href=“#” /><img src=‘./images/c1.jpg’ /></a></td>
</tr>
<tr>
<td>2</td>
<td>cat2</td>
<td><a id=“2” href=“#” /><img src=‘./images/c2.jpg’ /></a></td>
</tr>
</table>
<a id is dynamic i want when i click this image link i get the value of which link is clicked
regards.
Assuming you have assigned a function as an onclick handler for each of these links, you can use the this keyword to reference the link element. For example,
function myOnClickHandler() {
alert(this.id);
}
btw- a number is not a valid id.
http://www.w3.org/TR/REC-html40/types.html#type-name
thanks for reply,
i want to do it in jquery not in simple javascript
like
$(‘a’).click(function(){
$(this).attr(“id”);
})
but i want that this a should be call when click on a within this table not if i click on any other link .
regards
Give the table an ID first, then you can add the following jQuery:
$('#tableID a').click(function(){
alert(this.id);
});