I have following button on my view:
<td>
<?php
$data = array(
'name' => $id,
'class' => 'do_the_job',
'content' => 'Do the job'
);
echo form_button($data);
?>
</td>
When I click on that button it does what I expected because I have the following function in my EXTERNAL JS file
$(document).ready(function() {
$(".do_the_job").click(function() {
//does the job
});
});
I have also another controller and view and I created the button (with same class) for it dynamically using jQuery:
table.html('<button name="'+id+'" class="do_the_job">Do the job</button>');
The problem is that when I click on that button, it does not work despite the fact that the button has the same class as the first button and it is expected to do the work as it is described in my EXTERNAL JS file.
I have researched and saw that I should use the function on()
instead of click()
. I have modified my external JS file in the following way but it still does not work:
$(".do_the_job").on("click", function() {
//does the job
});
Could you please help me to solve the problem?