What could be wrong with my code. when I click the text enclosed with anchor tags. alert function is not showing up. but when i try console.log();
it shows the id in the console.
I generated the table data with php.
please help.
thanks
<tbody>
<?php
include('config.php');
$qry = $handler->prepare( "SELECT * FROM inspection WHERE inspect_status = ?");
$qry->execute(array('Booked'));
$row = $qry->rowCount();
while($row = $qry->fetch(PDO::FETCH_ASSOC)){
$iid = $row['inspect_id'];
$service = $row['inspect_service'];
$refno = $row['inspect_refnum'];
$insdate = $row['inspect_date'];
$intrno = $row['inspect_internalrno'];
$inspect_status = $row['inspect_status'];
?>
<?php
echo"
<tr>
<td>$iid</td>
<td>$refno</td>
<td>$intrno</td>
<td>$service</td>
<td>$insdate</td>
<td>
<a idd=$iid class='marks' href='?i=$iid'>Confirm</a>
</td>
</tr>
";
?>
<?php } ?>
<script type="text/javascript">
$(function () {
$('body').delegate('.marks', 'click', function () {
var idconf = $(this).attr('idd');
alert(idconf);
return false;
});
});
</script>
</tbody>
You should rather use .on()
for event delegation:
$('body').on('click','.marks',function(){
var idconf = $(this).attr('idd');
alert(idconf);
return false;
});
Try with -
$('.marks').on('click', function(e) {
alert($(this).attr('id'));
return false;
})
And change -
<a id=$iid class='marks' href='?i=$iid'>Confirm</a>
If you dont want to use id then you can try data
attribute also.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.