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.
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.
If you're adding them in code, you can use the .live() method (read the docs).
If they are being added to the DOM by a web service call, for example, then you can use event delegation. I'll leave it to you to read up on that! If you are adding piles of elements to the DOM, then event delegation is the way to go.