I am trying to achieve an on-click event on multiple buttons with the help of jQuery. These buttons are coming from php file.
php code:
<?php
require_once './common/db_connect.php';
$db_connection = db_connect();
$select_query = "SELECT term_id, term, status, active FROM term WHERE active = 1";
$statement = $db_connection -> query($select_query);
$result = $statement -> fetchALL(PDO::FETCH_OBJ);
foreach($result as $row) {
echo '<tr>';
echo '<td>'.$row->term.'</td>';
echo '<td><button value="'.$row->status.'">'.$row->status.'</button></td>';
echo '<td>'.(($row->active == 1) ? 'Yes' : 'No').'</td>';
echo '<td><button class = "delete" data-id='.$row->term_id.'>Delete</button></td>';
echo '</tr>';
}
?>
In the above code, I have a button with class="delete" and on this, I like to have an on-click event but it is not working.
jQuery code:
<script type="text/javascript">
$(function() {
$.ajax({
type: "GET",
url: "data.php",
success: function(data) {
$('tbody').html(data);
}
})
$('.delete').on('click', function() {
alert("this is working");
});
});
</script>