Insert into table and then click using Jquery

Asked

Viewed 265 times

0

I am inserting dynamically in my table, until then everything ok. The problem is when I try to click on one of the lines and I have no answer, I think I’m not entering in the DOM, someone could help me.

INSERTING:

$('#tabelaChat').append('<tr><td style="font-size: 9pt;">'+ data.flag[i].nome +'</td></tr>');

AT THE CLICK:

$('#tabelaChat tr').on('click', function(e){
                alert("Teste");          
                return false;
});
  • It is not very clear what the relationship of append with the click... Are you sure your data.flag[] contains data?

  • Brasofilo, the data is loading perfectly because it appears in the table. What didn’t happen was the click, I wasn’t getting add in the DOM, the answer was solved below. Thank you.

1 answer

1


Try to use it like this

$('#tabelaChat').on('click','tr', function(e){
                alert("Teste");          
                return false;
});
  • It worked! Thank you #vcrzy.

  • For nothing, friend, for you to do it that way, you should not use the on. Just $('#tableChat tr'). click(Function(){}); ok. Aprs

  • So I did the test with this second way, but it did not work. I will use with the 'on' that is ok. Thanks.

  • ahuhaua ta bom. thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.