Reputation: 824
What jQuery/JavaScript command can I use to detect whether the DOM (driven by a custom function) has been built before populating the fields inside it? Currently the latter fails unless I put in an alert box in between the 2 actions.
Upvotes: 3
Views: 1357
Reputation: 6949
You can look at document.readyState
. If the page is ready it should be "complete"
.
You can also use document.addEventListener('DOMContentLoaded', function () { })
Upvotes: 3
Reputation: 490223
$(function() { })
will tell you when the DOM is ready to be accessed.
If your custom function is adding things to the DOM, the best way would be to build something into it that notifies some code when it is done.
Upvotes: 6