Ecommerce Shopify WordPress Discussion

js isn't executing on first page load

I'm working with a WordPress site using the Divi theme. I have inserted a JavaScript code into the body via the theme options. However, I'm encountering an issue where the script doesn't executes until the second page load. Additionally, it doesn't seem to run at all when using Incognito mode. This script is intended to create interactive tooltips that respond to user actions, enhancing the user experience on the site. window.onload = function() { function getTooltipContent(id) { let content = ''; switch (id) { case 'Kreis1': // some text break; // Other cases default: content = ''; } return content; } const kreise = document.querySelectorAll('.svg-container g[id^="Kreis"]'); const infoContainer = document.getElementById('info-container'); const infoText = document.getElementById('info-text'); const svgContainer = document.querySelector('.svg-container'); kreise.forEach(kreis => { kreis.addEventListener('click', () => { const content = getTooltipContent(; infoText.innerHTML = content; // Tooltip content is set here if (window.innerWidth <= 768) { infoContainer.classList.add('info-container-mobile-active'); } else { infoContainer.classList.add('active'); svgContainer.classList.add('active'); } }); }); } I've tried using both the DOMContentLoaded event and the jQuery ready function to address this issue, but these approaches did not resolve the problem.
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.