Замена спецсимола в строке на слово
Подскажите, как заменить спецсимвол текстом.
<div class="cl" id="tid1"> DIV1 </div> <div class="cl" id="tid2"> DIV2 </div> <script type="text/javascript"> $(".cl").click(function(){ $temp = $(this).attr('id'); $(".cl").text(function(index, text) { return text.replace(" ", "SpecialChar"); }); }); </script> |
daslex,
<!DOCTYPE html> <html> <head> <title>Untitled</title> <meta charset="utf-8"> <style type="text/css"> </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script> $(function() { $(".cl").click(function(){ $temp = $(this).attr('id'); $(".cl").text(function(index, text) { return this.innerHTML.replace(" ", "SpecialChar"); }); }); }); </script> </head> <body> <div class="cl" id="tid1"> DIV1 </div> <div class="cl" id="tid2"> DIV2 </div> </body> </html> |
Спасибо!
|
Часовой пояс GMT +3, время: 19:21. |