0

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 .

Sourav Prem
  • 1,063
  • 13
  • 26

1 Answers1

1

Read the jquery on api you will find your answer.

and I am sure your button element are not present at the time of html render,

RonyLoud
  • 2,408
  • 2
  • 20
  • 25
Mukul Bhardwaj
  • 183
  • 1
  • 2
  • 8