0

I am dynamically generating HTML code and it works fine and I am sure that it contains the ID's that I am using.

However, I wrote some event listeners for these 2 dynamically generated ID's.

$("#dynamicID2").click(functionX);
$("#dynamicID3").click(functionX);

However, It doesn't work. Why is this? and how do I fix this?

Jay Jay
  • 57
  • 1
  • 11
  • One way would be `$(document).on('click', htmlclass, function(){})` but you have to use classes instead of ids. – Lixus Sep 27 '17 at 22:06
  • @Lixus, classes aren't required to delegate events. This would work just fine: `$(document).on('click', '#dynamicID2', function(){})` – Rick Hitchcock Sep 27 '17 at 22:09
  • What about adding an event to `dynamicID3` without writing another `on('click')` function or without doing this `'#dynamicID2, #dynamicID3'`? – Lixus Sep 27 '17 at 22:11

0 Answers0