Показать сообщение отдельно
  #4 (permalink)  
Старый 12.03.2023, 16:59
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,072

css includes text
Aidec,
<!DOCTYPE HTML>
<html>
<head>
    <title>Untitled</title>
    <meta charset="utf-8">
    <style type="text/css">
        table {
            border-collapse: collapse;
            border: 2px solid rgb(200, 200, 200);
            letter-spacing: 1px;
            font-family: sans-serif;
            font-size: 0.8rem;
        }
        td,
        th {
            border: 2px solid rgb(200, 200, 200);
        }
        td.red {
            background-color: #FF0000;
        }
    </style>
</head>
<body>
    <table>
        <caption>Alien football stars</caption>
        <tr>
            <th scope="col">Player</th>
            <th scope="col">Gloobles</th>
            <th scope="col">Za'taak</th>
        </tr>
        <tr>
            <th scope="row">TR-7</th>
            <td>7</td>
            <td>4,569</td>
        </tr>
        <tr>
            <th scope="row">Khiresh Odo</th>
            <td>7</td>
            <td>7,223</td>
        </tr>
        <tr>
            <th scope="row">Mia Oolong</th>
            <td>9</td>
            <td>6,219</td>
        </tr>
    </table>
    <script>
        let patern = '7';
        document.querySelectorAll('td').forEach(td => {
            let txt = td.textContent;
            td.classList.toggle('red', txt.includes(patern))
        })
    </script>
</body>
</html>
Ответить с цитированием