- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
The increasing use of Angular, Knockout, and other dynamic content libraries has been causing some issues with manipulating and scraping content from page elements that are created after the DOM Ready signal has already fired.
If your site is running jQuery, we can use the waitUntilExists (WUE) plugin to make an extension wait for an element to be created before running its code. This is much more effective than waiting for window.onload because, with some heavier pages, a visitor will have already navigated away before that signal can fire.
(function(e, f) { var b = {}, g = function(a) { b[a] && (f.clearInterval(b[a]), b[a] = null) }; e.fn.waitUntilExists = function(a, h, j) { var c = this.selector, d = e(c), k = d.not(function() { return e(this).data("waitUntilExists.found") }); "remove" === a ? g(c) : (k.each(a).data("waitUntilExists.found", !0), h && d.length ? g(c) : j || (b[c] = f.setInterval(function() { d.waitUntilExists(a, h, !0) }, 500))); return d } })(jQuery, window);
$("#yourSelector").waitUntilExists(function() { /* Your JS */ });
If your selector is not unique and is likely to set off the WUE statement multiple times, make sure to set up some logic that will ensure that your code only runs on the first (or whichever) passthrough.
Copyright All Rights Reserved © 2008-2023