Execute JavaScript function in the click event of a button inside a table

Posted on

Question :

Hello, I have a table and in each row of this table I have a button, when I click that button I need to execute a function but I can not do that because I do not think I’m using the correct selectors. p>

Table:

<table id="tbl" class="table table-striped">
    <tr id="cabecalho">
        <th>
            ID
        </th>
        <th>
            Insumo
        </th>
        <th>
            TD
        </th>
        <th>
            Unidade
        </th>
        <th>
            Quantidade
        </th>
        <th>
            Adicionar
        </th>
    </tr>
</table>

Script that generates the table body:

$('#pesquisar').click(function () {
$('.corpoTbl').remove();
$.ajax({
url: "/RCM/ListarMateriais",
type: "POST",
data: { nome: $('#NomeMaterial').val() },
datatype: 'json',
success: function (data) {
$.each(data, function (I, item) {
$('#tbl').append("<tr class="corpoTbl"">

Answer :

<

td class=""id"">

+ item.ID + ""<

/td>

<

td>

+ item.Nome + ""<

/td>

<

Leave a Reply

Your email address will not be published. Required fields are marked *