Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Добавить класс к таблице но не ко всем td (https://javascript.ru/forum/dom-window/81745-dobavit-klass-k-tablice-no-ne-ko-vsem-td.html)

Nexus 22.01.2021 14:54

<button id="set-notranslate-class-fot-table-cell-button">Set «notranslate» class for table cells</button>

<script>
    document.addEventListener('DOMContentLoaded', () => {
        const button = document.querySelector('#set-notranslate-class-fot-table-cell-button');
        if (!button) return;

        button.addEventListener('click', () => {
            const htmlString = prompt('Enter your HTML table');
            if (!htmlString || !htmlString.trim().length) return;

            const container = document.createElement('div');
            container.innerHTML = htmlString;

            container.querySelectorAll('tbody tr').forEach((row, rowIndex) => {
                row.querySelectorAll('td').forEach((cell, cellIndex) => {
                    if (cellIndex) cell.classList.add('notranslate');
                });
            });

            prompt('Take your prepared table', container.innerHTML);
        });
    });
</script>

Alexprom 22.01.2021 14:56

Цитата:

Сообщение от Nexus (Сообщение 533062)
<button id="set-notranslate-class-fot-table-cell-button">Set «notranslate» class for table cells</button>

<script>
    document.addEventListener('DOMContentLoaded', () => {
        const button = document.querySelector('#set-notranslate-class-fot-table-cell-button');
        if (!button) return;

        button.addEventListener('click', () => {
            const htmlString = prompt('Enter your HTML table');
            if (!htmlString || !htmlString.trim().length) return;

            const container = document.createElement('div');
            container.innerHTML = htmlString;

            container.querySelectorAll('tbody tr').forEach((row, rowIndex) => {
                row.querySelectorAll('td').forEach((cell, cellIndex) => {
                    if (cellIndex) cell.classList.add('notranslate');
                });
            });

            prompt('Take your prepared table', container.innerHTML);
        });
    });
</script>

Да, то что нужно))) Большое вам спасибо!!!) И очень хорошего дня))):victory:

sainivedant 05.02.2021 15:35

Написать скрипт, который проставляет определенный класс определенным элементам таблицы - не проблема. Проблема в том, что вам нужно модифицировать разметку в визуальном редакторе. mobdro

Regards, tubemate


Часовой пояс GMT +3, время: 07:56.