javascript - Find and replace dollar sign with rupee symbol using jQuery - Stack Overflow

This is my code in which I am trying to replace Dollar Symbolwith INR(Indian Rupee) using jQuery, how

This is my code in which I am trying to replace Dollar Symbol $ with INR(Indian Rupee) using jQuery, however it is not working as this is only a specimen code so it is not ul >li and find text and replace text kinda thing, my tries goes like this- I tried to first gather whole HTML and then replace $ sign with the code, but its not making anyhow.

My assumption - in $(document).ready() using $(this) inside this snippet refers to the document, let me know if this is a false assumption, as I tried my attempts keeping this thing in mind.

Please DO NOT give any links/referrals to do it in CSS way or Webrupee API usage, keep it simple to jQuery this time :)

My Code -

<!DOCTYPE html>
<html>
<head>
    <title>Rupee Change - jQuery Flavour</title>
</head>

<body>
<p>This is a price listing with &#36; sign, Now I wanted to replace each dollar sign with rupee symbol</p>
<ul>
<li>&#36; 500</li>
<li>&#36; 600</li>
<li>&#36; 700</li>
<li>&#36; 800</li>
<li>&#36; 900</li>
</ul>

 <div id="showhtml"></div>
<script src=".js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(this).html().replace("$", "<del>&#2352;</del>");
});
</script>
</body>
</html> 

FYI - I also tried this way of handling but not working :( find-text-string-using-jquery

This is my code in which I am trying to replace Dollar Symbol &#36; with INR(Indian Rupee) using jQuery, however it is not working as this is only a specimen code so it is not ul >li and find text and replace text kinda thing, my tries goes like this- I tried to first gather whole HTML and then replace $ sign with the code, but its not making anyhow.

My assumption - in $(document).ready() using $(this) inside this snippet refers to the document, let me know if this is a false assumption, as I tried my attempts keeping this thing in mind.

Please DO NOT give any links/referrals to do it in CSS way or Webrupee API usage, keep it simple to jQuery this time :)

My Code -

<!DOCTYPE html>
<html>
<head>
    <title>Rupee Change - jQuery Flavour</title>
</head>

<body>
<p>This is a price listing with &#36; sign, Now I wanted to replace each dollar sign with rupee symbol</p>
<ul>
<li>&#36; 500</li>
<li>&#36; 600</li>
<li>&#36; 700</li>
<li>&#36; 800</li>
<li>&#36; 900</li>
</ul>

 <div id="showhtml"></div>
<script src="http://code.jquery./jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(this).html().replace("$", "<del>&#2352;</del>");
});
</script>
</body>
</html> 

FYI - I also tried this way of handling but not working :( find-text-string-using-jquery

Share Improve this question edited May 23, 2017 at 11:57 CommunityBot 11 silver badge asked Apr 20, 2013 at 12:11 swapneshswapnesh 26.7k24 gold badges97 silver badges129 bronze badges 2
  • 1 you need to reassign it back to the html. $(this).html($(this).html().replace("$", "<del>&#2352;</del>")); – Parthik Gosar Commented Apr 20, 2013 at 12:30
  • @ParthikGosar not working :( – swapnesh Commented Apr 20, 2013 at 12:33
Add a ment  | 

1 Answer 1

Reset to default 4

$ is a special character in Regex. You will need to escape it.

$(document).ready(function(){
    var replaced = $('body').html().replace(/\$/g, "<del>&#2352;</del>");
    $('body').html(replaced);
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745522837a4631338.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信