convert .click to on click jquery ajax

Viewed 50
        $('#myTable').find('td').click(function() { 

            $('#meaningtextarea').val($("[type='hidden']", this).val());
            
        });

I need to convert this event to below format. could you please help me with this.

$(document).on('click', '#element', function (evt) {
    
});
1 Answers

Try this:

$(document).on('click', '#myTable td', function(e){
  console.log($(this).text())
})
table, tr, td {
  border : 1px solid black;
  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Target table -->
<table id="myTable">
  <tr>
    <td>aa</td>
    <td>bb</td>
  </tr>
</table>
<p>

<!-- Test table -->
<table >
  <tr>
    <td>xx</td>
    <td>zz</td>
  </tr>
</table>

Related