jQuery selecting elements that don't yet exist

jquery

Solution

You can bind events to elements that don't yet exist using .on(); but other than that, I don't think you've got much of a solution.

What are you trying to do exactly?

$(document).on("click", "#futureID", function(){
  /* whenever <a id='futureID'>Hello</a> is created,
     it will have this functionality */
});

/* Sometime in the future, you add the link */
$("body").append("<a href='index.php' id='futureID'>Hello</a>");

That link would have the aforementioned functionality already connected.

Problem

In jQuery I want to be able to select an element that does not even exist yet, how can I accomplish this? I would like to select an element by their id when they are created. Thanks.

Original source

Related problems