Перебор элементов табилцы
Подскажите что ни так ?
Есть таблица у неё есть ячейки и вних есть строки с классом : del_sl Надо у всех строк в самом начале убрать символ / Делаю так вот, но в итоге все строки заменяются самой первой: jQuery('.del_sl').each(function(){ var s = jQuery(this).html(); var s = s.replace(/[\/]/g, ''); jQuery('.del_sl').html(s); }); |
всё понял. надо так вот:
jQuery('.del_sl').each(function(){ var s = jQuery(this).html(); var s = s.replace(/[\/]/g, ''); jQuery(this).html(s); }); |
morgusha,
document.querySelectorAll('.del_sl').forEach(el => el.textContent = el.textContent.replace(/[\/]/g, '')) |
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, время: 01:05. |