document.addEventListener('DOMContentLoaded', () => { const toggleCheckbox = document.querySelector('.toggleMainCheckbox'); const secMBSI_DSMPremiumSecMidCardsInside = document.querySelector('.secMBSI_DSMPremiumSecMidCardsInside'); if (!secMBSI_DSMPremiumSecMidCardsInside) { console.error('secMBSI_DSMPremiumSecMidCardsInside not found'); return; } const children = Array.from(secMBSI_DSMPremiumSecMidCardsInside.children); if (children.length < 2) { console.error('Not enough children in secMBSI_DSMPremiumSecMidCardsInside'); return; } const secondChild = children[1]; const lastChild = children[children.length - 1]; function updateContent() { const updateLastP = (card, h1Content, pContent) => { const cardTop = card.querySelector('.secMBSI_DSMPremiumSecMidCardsCardTop'); const lastP = cardTop.querySelectorAll('p').length > 0 ? cardTop.querySelectorAll('p')[cardTop.querySelectorAll('p').length - 1] : null; const h1 = cardTop.querySelector('h1'); if (h1) { h1.innerHTML = h1Content; } if (lastP) { lastP.innerHTML = pContent; } }; if (toggleCheckbox.checked) { // Update second child updateLastP(secondChild, '€300€250%16 off', '€25€20.83 per month for 12 months'); // Update last child updateLastP(lastChild, '€180€150%16 off', '€15€12.5 per month for 12 months'); } else { // Revert second child updateLastP(secondChild, '€25', '€25 per month'); // Revert last child updateLastP(lastChild, '€15', '€15 per month'); } } toggleCheckbox.addEventListener('change', updateContent); // Initial update based on the current checkbox state updateContent(); });