Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Замена спецсимола в строке на слово (https://javascript.ru/forum/jquery/67072-zamena-specsimola-v-stroke-na-slovo.html)

daslex 26.01.2017 22:27

Замена спецсимола в строке на слово
 
Подскажите, как заменить спецсимвол текстом.
<div class="cl" id="tid1">
			DIV1 &nbsp;
		</div>

		<div class="cl" id="tid2">
			DIV2 &nbsp; 
		</div>



<script type="text/javascript">
	$(".cl").click(function(){
		$temp = $(this).attr('id');
		
		$(".cl").text(function(index, text) {
			return text.replace("&nbsp;", "SpecialChar"); 
		});
		
	});
 </script>

рони 27.01.2017 05:44

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("&nbsp;", "SpecialChar");
    });

  });
});
  </script>
</head>

<body>
<div class="cl" id="tid1">
      DIV1 &nbsp;
    </div>

    <div class="cl" id="tid2">
      DIV2 &nbsp;
    </div>

</body>
</html>

daslex 27.01.2017 14:29

Спасибо!


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