JavaScript:。点击不工作(PHP)

Afternoon everyone,

I am having a bit of problem with my code, basically trying to console.log() something when I click a button. Here is the code :

echo '<td><button type="button" class="btn btn-danger  delete delete-category"><i class="fa fa-trash-o fa-lg"></i> Delete</button> 
          <input type="hidden" value="'. $car_makes['car_make_id'] .'"  name="delete[]">
      </td>'

As you can see I am using PHP to show the button. Button is showing up and I get my value in the hidden field.

Code :

$('button.delete-category').click(function(e) {
    console.log("sss");
});

Whenever I click the button no sort of console or any event is getting triggered.

I believe I have shared everything but if you need any more information please comment and thanks in advance.

First add a "return false;" after your console.log() otherwise the page might be submitted as soon as you click and then you wouldn't see the console output in time, second make sure your .click() binding is executed at the right time, you can add an alert('step1') before and after it to make sure it is executed and no errors hapens.

Also make sure it is execute after DOM ready, for jQuery:

$(function() {
  alert('step1');
  $("button.delete-category").click(function() {
    alert('step3');
    console.log("sss");
    return false;
  });
  alert('step2');
});