I want to create a set of elements to add to a HTML document using JQuery’s $(document.createElement()). I know $(document).ready() is required before starting using document elements.
However, is it necessary to use $(document).ready() in order to create elements with $(document.createElement())? In other word, can I use $(document.createElement()) in a document before it is ready?
You can create a new node at any time. But if you’re going to be inserting it into the page’s DOM, then you’ll have to use .ready(), otherwise there’s no guarantee that the spot you’re trying to insert into exists yet.