I want to returning the clicked element's "data-id" attribute value with jquery but this code is returning all id from the loop not only the clicked element's id
<?php
$datas = get_users_data(); // this is returning an array from MySQL like user's id, username etc...
foreach ($datas as $data) {
$id = $data["id"];
?>
<td><a href="#" id="edit" data-id="<?php echo $id; ?>" class="edit">Edit</a></td>
<?php } ?>
<script>
$(document).on('click', '.edit', function(event){
event.preventDefault();
alert($(this).attr("data-id"));
});
</script>