JQuery: Appending to an element created in another function
问题 I created a div like so: $(document).ready(function() { $(document.createElement("div")).attr("id", "container").appendTo("body"); }); and then later, dynamically I want to append some stuff to it, so in another function I call $(newElement).appendTo("#container"); but it doesn't do anything. The div is still there, but it is empty. If I change the code to $(newElement).appendTo("body"); it works fine. Any ideas on what I'm doing wrong? Here is a full example of my code: <html xmlns="http:/