Skip to content

waitFor an element to load into the DOM before doing the changes

Osvaldo edited this page Jan 4, 2026 · 1 revision

Sometimes you may need to define an experiment before an element is available in the DOM. For example when you define the experiment in a Wordpress html block and the changed elements aren't created yet.

Abrantes provides the waitFormethod to do the changes only after the element is loaded. Please see the example for more information.

// Variant 1 (changes are made only after the element is available)
function () {
    MyTest.waitFor("#bigH1",  () => {
        document.getElementById("bigH1").innerText = "MyTest Variant 1";
    });
}

You can use multiple waitFor to wait for different DOM elements.

Clone this wiki locally