After dynamically appending a chunk of HTML to a document (Example uses jQuery, but question is valid for all JavaScript), can I assume that the appended elements are available immediately afterwards?
$('#content').append('<p>Content</p><button id="newbutton">New</button><p>Some more content</p>');
var forExample = $('#newbutton').width(); // Element available?
In my particular case, creating single elements is not practicable. Also, this is long past the document.ready event.
Yes, they’re available immediately. jQuery will return you the correct objects, for example, and you may bind elements onto them.
But as they’re not rendered while your script is running, size computations aren’t always immediately made, so if you need the dimensions of the objects you might have to do
Note that the behavior of browser is different if you’re incrementally debugging (the script isn’t really “running”).