1
This is my jQuery that builds HTML into my cshtml.
$(data.resultado).each(function () {
str += '<tbody>';
str += '<tr>';
str += '<td>';
str += '<label style="font-size:10px"><a href="#">' + data.resultado[cont].CNPJ + '</a></label>';
str += '</td>';
str += '<td>';
str += '<label style="font-size:10px"><a href="#">' + data.resultado[cont].RazaoSocial + '</a></label>';
str += '</td>';
str += '</tr>';
str += '</tbody>';
cont++;
});
How do I click on a column (CNPJ or Razasocial), it feeds one or another Hidden field equivalent to column.
So I put the code passed to me and no Alert comes when I click on the corresponding td. tblGrid is the name of my table. I did so and nothing in Alert
$('#tblGrid').on('click', 'td', function (e) {
var ancora = $(this).find('label a');
var valor = ancora.text();
alert(valor);
// e agora use o valor como quiser
});
Click on a column or cell? What do you want as the value of the Hidden field?
– bfavaretto
Please avoid metamorphosing the question as you try the answers. In this case I suppose the very one
#tblGrid
is being dynamically inserted, no? Try$(document).on(...
to confirm that this is the problem.– bfavaretto
The following is supplementary to the question original with more information is highly desirable. Changing the question with the progress of its solution as you try the suggestions of the answers is not desirable, because the question becomes another. In this case, you could comment below my reply with something like: "I tested this code using
#tblGrid
as selector and Alert inside with value, but Alert does not appear".– bfavaretto
Well, I saw that you accepted my answer. It worked now?
– bfavaretto