To handle an onClick event on a Webflow button and set the background color of a new div, you can use custom JavaScript. Here’s how to do it:
my-button
).my-div
).tag section.
<script> document.addEventListener("DOMContentLoaded", function () { const button = document.getElementById('my-button'); const targetDiv = document.getElementById('my-div'); if (button && targetDiv) { button.onclick = function () { // Optional: show the div if it's hidden targetDiv.style.display = 'block'; // Set background color targetDiv.style.backgroundColor = '#3498db'; // Example: blue }; } });</script>
Attach a unique ID to both your button and div in Webflow, then use JavaScript placed in the Page Settings to listen for the button’s click event and update the target div's background color dynamically.