scripts/index.js
/** Update the counter's display */
Update the counter's display
Update the counter ' s display
function updateCounters() {
    $(".counter-button").each((index, counterButton) => {
        let display = $(`#${counterButton.getAttribute("data-display")}`);
        let number = parseInt(display.attr("data-value"));
        if (counterButton.classList.contains("counter-increment-button")) {
            if (number >= 999 || isNaN(number)) {
                counterButton.setAttribute("disabled", true);
            } else {
                counterButton.removeAttribute("disabled");
            }
        }
        if (counterButton.classList.contains("counter-decrement-button")) {
            if (number <= 1 || isNaN(number)) {
                counterButton.setAttribute("disabled", true);
            } else {
                counterButton.removeAttribute("disabled");
            }
        }
    });
    $(".counter-display").each((index, display) => {
        display.innerHTML = $(display).attr("data-value");
    });
}
function updateCounters ( ) { $ ( ".counter-button" ) . each ( ( index , counterButton ) => { let display = $ ( ` ${ counterButton . getAttribute ( "data-display" ) } ` ) ; let number = parseInt ( display . attr ( "data-value" ) ) ; if ( counterButton . classList . contains ( "counter-increment-button" ) ) { if ( number >= 999 || isNaN ( number ) ) { counterButton . setAttribute ( "disabled" , true ) ; } else { counterButton . removeAttribute ( "disabled" ) ; } } if ( counterButton . classList . contains ( "counter-decrement-button" ) ) { if ( number <= 1 || isNaN ( number ) ) { counterButton . setAttribute ( "disabled" , true ) ; } else { counterButton . removeAttribute ( "disabled" ) ; } } } ) ; $ ( ".counter-display" ) . each ( ( index , display ) => { display . innerHTML = $ ( display ) . attr ( "data-value" ) ; } ) ; }
Update the counter's display
Update the counter ' s display
// Update each counter display