I have a list of <img>
tags with each of them contains different id. This is done using PHP for loop as shown below:
<?php
for($n=0; $n<=5; $n++)
{
?>
<img id="<?php echo 'time_'.$n; ?>" src="$output-mp4_thumbnails-$n.jpg">
<?php
}
?>
I want to use jQuery in such a way that, when I click on the specific image on my browser, it would print out the id accordingly. Below is how I code it:
$(document).ready(function () {
$("img").click(function () {
alert($("img").attr("id"));
});
});
However this keeps printing only the first id, which is time_0
. I have been looking around for ways to solve this, and I found out about change()
, but it can only be used for form inputs.
Any suggestions will be greatly appreciated.