Snippets Collections
const toggleClass = (element, className, force) => {
     element.classList.toggle(className, force);
    };


const div = document.querySelector("div");

// Toggle the class "active" on the div
toggleClass(div, "active");

// Force add the class "highlight"
toggleClass(div, "highlight", true);

// Force remove the class "hidden"
toggleClass(div, "hidden", false);



        const box = document.querySelector(".box");
        const button = document.getElementById("toggleBtn");

        button.addEventListener("click", () => {
            toggleClass(box, "active");
        });




 const toggleSpan = (currentTarget, force = true) => {
        const compareBlock = currentTarget.closest(".compare-block");
        if (!compareBlock) return;

        const currentSpan = compareBlock.querySelector("span");
        if (currentSpan) {
            toggleClass(currentSpan, "show", force);
            if (currentSpan.className.indexOf("show") > -1) {
                currentSpan.setAttribute("aria-hidden", "false");
            } else {
                currentSpan.setAttribute("aria-hidden", "true");
            }
        }
    };
star

Thu Feb 13 2025 02:20:11 GMT+0000 (Coordinated Universal Time)

#toggle #force
star

Fri Mar 24 2023 06:37:16 GMT+0000 (Coordinated Universal Time)

#optimizely #force #tracking #true
star

Tue Feb 07 2023 03:17:17 GMT+0000 (Coordinated Universal Time)

#optimizely #force
star

Tue Feb 07 2023 03:15:58 GMT+0000 (Coordinated Universal Time)

#draft #optimizely #force #public

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension