# tableberg/1.1.5/src/blocks/toggle/frontend.ts

Tableberg – Simple Gutenberg Table Block, version 1.1.5. 61 lines.

- Page: https://pluginprobe.com/plugins/tableberg/1.1.5/code/src/blocks/toggle/frontend.ts
- Raw: https://pluginprobe.com/plugins/tableberg/1.1.5/raw/src/blocks/toggle/frontend.ts
- Modified: 2026-09-16T03:30:32+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tableberg/1.1.5/code/src/blocks/toggle/frontend.ts#L10-L20`.

```typescript
document.addEventListener("DOMContentLoaded", () => {
    const tabBlocks = document.querySelectorAll<HTMLElement>(".tab-block");

    tabBlocks.forEach(tabBlock => {
        const activeBackground = tabBlock.dataset.activeBackgroundColor;
        const activeColor = tabBlock.dataset.activeColor;
        const inactiveBackground = tabBlock.dataset.backgroundColor;
        const inactiveColor = tabBlock.dataset.color;

        const tables = tabBlock.querySelectorAll<HTMLElement>(
            ".wp-block-tableberg-toggle > .wp-block-tableberg"
        );
        const headings = tabBlock.querySelectorAll<HTMLElement>(".tab-heading");

        tables.forEach(table => {
            table.style.display = "none";
        });

        headings.forEach((heading, index) => {
            heading.style.setProperty("color", inactiveColor ?? null);
            heading.style.setProperty(
                "background-color",
                inactiveBackground ?? null
            );

            if (heading.classList.contains("active")) {
                tables[index].style.display = "block";
                heading.style.setProperty("color", activeColor ?? null);
                heading.style.setProperty(
                    "background-color",
                    activeBackground ?? null
                );
            }

            heading.addEventListener("click", () => {
                tables.forEach(tab => {
                    tab.style.display = "none";
                });

                tables[index].style.display = "block";

                headings.forEach(heading => {
                    heading.classList.remove("active");
                    heading.style.setProperty("color", inactiveColor ?? null);
                    heading.style.setProperty(
                        "background-color",
                        inactiveBackground ?? null
                    );
                });

                heading.classList.add("active");
                heading.style.setProperty("color", activeColor ?? null);
                heading.style.setProperty(
                    "background-color",
                    activeBackground ?? null
                );
            });
        });
    });
});

```
