Home / Admin / Remove Decimal Points In Suggested (US)
Duplicate Snippet

Embed Snippet on Your Site

Remove Decimal Points In Suggested (US)

Will turn "$5.00" into "$5" on suggestion donation amounts in the donation form.

Code Preview
js
document.addEventListener('DOMContentLoaded', function () {
    // Select all span elements inside the ul with the class 'donation-amounts'
    const amountSpans = document.querySelectorAll('.donation-amounts span.amount');
    amountSpans.forEach(span => {
        // Get the current text content
        let value = span.textContent;
        // Find the index of the decimal point
        const decimalIndex = value.indexOf('.');
        // If a decimal point is found, remove it and everything after it
        // If no decimal point, leave the value as is
        if (decimalIndex !== -1) {
            value = value.substring(0, decimalIndex);
        }
        // Update the span's text content with the new value
        span.textContent = value;
    });
});

Comments

Add a Comment