When a button on a WordPress site looks fine in the code but doesn’t actually work on the live site, the cause is often deeper than simple HTML. This case study highlights how the Freshy support team diagnosed and resolved a stubborn JavaScript override issue affecting a call-to-action button inside a static calculator tool.
Issue background
A client reached out regarding their “Talk to an Expert” button on a custom-built Savings Calculator page. Despite updating the button’s link in the HTML file (/assets/calc/index.html), the change wasn’t sticking. Even after clearing caches in their optimization/caching plugin and web hosting platform, the button remained non-functional.
The calculator itself was a standalone HTML/JS asset embedded within the WordPress environment — likely using custom JavaScript for interactive calculations. That setup introduced an additional layer of complexity, since custom scripts can sometimes overwrite DOM changes on page load.
Diagnosis
Upon investigation, the development team confirmed the following:
- The button element existed in a static HTML file, separate from typical WordPress templates.
- The site’s calculator scripts were reinitializing or overwriting the button’s attributes (such as
hrefandonclick) during page load. - Directly modifying the HTML file didn’t solve the issue, because the JavaScript controlling the calculator re-rendered the button after every load or calculation event.
To confirm this, the developer used browser DevTools to monitor the DOM changes — and sure enough, the button’s href attribute was being removed seconds after page load.
Resolution steps
To ensure the “Talk to an Expert” button redirected users properly, the developer implemented a JavaScript event listener that triggered the redirect after the calculator script loaded. This method avoids conflicts by waiting for the calculator’s own scripts to finish before applying the intended functionality.
document.addEventListener('DOMContentLoaded', function() {
const expertBtn = document.querySelector('.talk-to-expert');
if (expertBtn) {
expertBtn.addEventListener('click', function() {
window.location.href = '/contact/';
});
}
});
This approach attaches a persistent click listener that remains functional even if the calculator script reinitializes the DOM, solving the override problem.
After implementation, the site was retested — including cache purging and a full browser refresh — and the button worked as expected.
Final outcome
Once the JavaScript listener was deployed, the “Talk to an Expert” button correctly redirected to the site’s Contact page, and the client confirmed everything was functioning properly.
This case illustrates how dynamic JavaScript elements within static HTML modules can inadvertently block front-end updates. When traditional fixes (like editing HTML or clearing caches) don’t work, leveraging event listeners or deferred scripting can provide a more resilient solution.
Need help troubleshooting a similar front-end or JavaScript issue? Contact Freshy to get expert support with your WordPress integrations, calculators, and custom scripts.
Recommended tags:
WordPress, JavaScript, HTML, DOM manipulation, button not working, caching plugin, event listener, front-end debugging