Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Перебор элементов табилцы (https://javascript.ru/forum/jquery/82660-perebor-ehlementov-tabilcy.html)

morgusha 08.06.2021 13:01

Перебор элементов табилцы
 
Подскажите что ни так ?
Есть таблица у неё есть ячейки и вних есть строки с классом : del_sl
Надо у всех строк в самом начале убрать символ /
Делаю так вот, но в итоге все строки заменяются самой первой:

jQuery('.del_sl').each(function(){
var s = jQuery(this).html();
var s = s.replace(/[\/]/g, '');
jQuery('.del_sl').html(s);
});

morgusha 08.06.2021 13:06

всё понял. надо так вот:
jQuery('.del_sl').each(function(){
var s = jQuery(this).html();
var s = s.replace(/[\/]/g, '');
jQuery(this).html(s);
});

рони 08.06.2021 13:44

morgusha,
document.querySelectorAll('.del_sl').forEach(el => el.textContent = el.textContent.replace(/[\/]/g, ''))

рони 08.06.2021 13:53

morgusha,
<!DOCTYPE html>

<html>
<head>
    <title>Untitled</title>
    <meta charset="utf-8">
    <style type="text/css">
    </style>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script>
jQuery(function() {
jQuery('.del_sl').text((i, txt) => txt.replace(/[\/]/g, ''));
});
    </script>
</head>

<body>
<table>
    <tr>
        <td class="del_sl">/test1</td>
    </tr>
    <tr>
        <td class="del_sl">/test2</td>
    </tr>
    <tr>
        <td class="del_sl">/test3</td>
    </tr>
    <tr>
        <td class="del_sl">/test4</td>
    </tr>
    <tr>
        <td class="del_sl">/test5</td>
    </tr>
</table>

</body>
</html>


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