Varify logo

Code Helpers

In short

Code Helpers will help you as a web developer to set up A/B tests, especially when developing A/B tests for single page applications. 

JavaScript Helper Functions


With the function waitFor a mutation observer is used to wait for a defined element. As soon as new elements matching the defined selector are added to the DOM (e.g. by AJAX or JavaScript), the callback function is executed.

The callback function is called for each newly identified element. 

Code example

  <p>This is existing content.</p>
  <!-- <p class="lazyloaded-content">This content will be loaded later.</p> -->
					window.varify.helpers.waitFor('.lazyloaded-content', (element) => {
  // After the content was loaded, we want to color it red. = 'red';


This function calls the CallBack every time elements are added or deleted in the DOM. It is also based on a Mutation Observer. 

					window.varify.helpers.onDomChanged(() => {
  // Write code here, which will run everytime the dom changes.


This function calls the callback as soon as the DOM is loaded. If the DOM is already loaded, the callback is called immediately.

					window.varify.helpers.onDomLoaded(() => {
  // Write code here, which will run when the DOM has loaded.


With the function isInView  is waited for a given DOM element to be fully visible in the viewport. The callback is executed only once by default, but can optionally be executed every time the element is in the viewport. 

					// The callback here will be triggered ONE TIME, when the element is in view.
window.varify.helpers.isInView('.product', (element) => {
    event: 'product viewed',

// Adding true as third parameter
// will trigger the callback EVERY TIME the element is in view.
window.varify.helpers.isInView('.product', () => {}, true);


This function resets all observers (intersection and mutation observer) of the above functions. Thus, the defined callback functions are no longer executed.

					// As an example, we setup a waitFor listener here. This will use a MutationObserver under the hood.
window.varify.helpers.waitFor('.lazyloaded-content', (element) => { = 'red';

// The next resetting function call could e.g. be located in a navigation callback function.


Function overview