0

I am trying to write html code using jquery but this code for a functional button seems to not work for me, I have added the button functionality and works fine when the same line(as below) is written in .html file.

function()
{
  var html '<div>';
  html += '<button id="add-button" type="button" role="button">ADD</button>';
  html += '</div>'
  $("#id").append( html );
}
Vinita
  • 1,834
  • 2
  • 8
  • 20
  • 1
    To have event handlers work on dynamically created elements you need to use delegated event handlers. See the duplicate I marked for more information – Rory McCrossan Aug 16 '20 at 15:46
  • 1
    Also note that you need to avoid duplicating `id` attributes, so you would be best to remove the `id` attribute from the HTML you create dynamically and rely on classes/parent selectors instead – Rory McCrossan Aug 16 '20 at 15:47

0 Answers0