Reputation: 48
I have a PHP table generated using a MySQL database, I want to run a jquery function by clicking on a button placed in a field in the table. Since the button id is dynamic, Is there a way to trigger the button id and run the jQuery?
PHP Code :
echo "<td>
<button id='".$row['S_No']."'value='".$row['S_No'].">".$row['S_No']."</button></td>";
JQuery Code:
$(document).ready(function(){
$("#buttonId").click(function(){
// Code goes here
});
});
Upvotes: 0
Views: 38
Reputation: 828
Use class instead id
echo "<td>
<button class="btn-class" id='".$row['S_No']."'value='".$row['S_No'].">".$row['S_No']."</button></td>";
$(document).ready(function(){
$(".btn-class").click(function(){
// Code goes here
});
});
Upvotes: 1