datatablesjquery-onyajra-datatable

jQuery cannot catch the DataTable button class in Laravel


The button in td is from the DataTable Ajax back data:

<button type="button" class="btn btn-default downpraise " data-toggle="tooltip"  data-placement="top" title="downbutton" name="downtest">
      <i class="far fa-thumbs-down">data</i>
</button>

My funtion is:

$('button[name="downtest"]').on('click',function(){
    console.log("downbutton push1);
})

or

$(".downpraise").on('click', function() {
    console.log("downbutton push2);
})

The above two do not get any responses? Any clues?

PS:

columns: [
          { data: 'action',  render: function ( data ) {              

        return  '<button type="button" class="btn btn-default downpraise " data-toggle="tooltip"  data-placement="top" title="downbutton" name="downtest">
             <i class="far fa-thumbs-down">data</i>
       </button>'
  ]

Solution

  • I solve the question by

    $(document).on( 'click', 'button.downpraise', function () {
    }
    

    I don't know why the original method cannot work.