0

I'm using code from a previous question located at Create Dynamic div with unique IDs - jQuery. The question when asked used jquery 1.4.2 but I am using jquery 3.4.1.

I changed the

$("input").live("click", function() { $("span").text("Clicked ID: " + this.id);});

to

$("input").on("click", function() { $("span").text("Clicked ID: " + this.id);});

But when you click on the input field now the text is not added to the span tag.

Here is my code on Fiddle https://jsfiddle.net/shammock3522/xyjwg4em/2/

Stephen
  • 21
  • 4
  • Your code should not be behind a link. Please take some time to create a runnable snippet inside the question using the toolbar in the editor. – trincot Dec 19 '21 at 12:32
  • 2
    What you don't mention in your question is that the inputs are added after the event binding. Change `$("input").on("click", function...` to `$(document).on("click", "input", function...`. https://jsfiddle.net/9zjnf6y8/ Also, don't use dynamic IDs, you don't need them, it's the `name=` that's relevant and you already change that. – freedomn-m Dec 19 '21 at 12:34
  • Thank you trincot for correcting me on the snippet and freedomn-m for the solution. The $(document).on works. I knew it was something simple. – Stephen Dec 20 '21 at 14:51

0 Answers0