I have a piece of code where elements are generated in a for loop (PHP). The code is:
for($i=0; $i < $count; $i++)
{
$member = $my_array[$i];
<td><span id="myspan"><input type="text" id="username" value="<?php echo $member; ?>" /></span></td>
}
In my jquery code, I am trying to read the value of the clicked element but it is returning the value of the first element and not the value of the clicked element. I guess this is happening because the id of each element is the same. But then how to get the value of the clicked element?
My jQuery code is:
$("#myspan").click(function(){
alert(username);
});
Any pointers will be much appreciated?