I have a button in a datatable. I have a class attached to it . All the rows of the data table has this button field with different field id and same class.I just want to print the id of the button on its click.
'<button class="link" id="field1">'+field1+'</button>';
'<button class="link" id="field2">'+field2+'</button>';
When i make the call using $(".link").click(function(){ console.log(this.id)};
it does nothing.
But when i make the call using $(document).on('click','.link',function(){
console.log(this.id)}
it worked . So i want to know the difference why the second one works and the first one doesn't work . Here this Difference between .on('click') vs .click() question says that both are functionally same, So what might be the reason in this case .