0

I have a tricky situation in that the shopping cart I am using switches from US ($) to South African (R) randomly. The guys who make this cart cannot give me an answer as to when they will be able to fix this, let alone know where the bug is.

What I need to be able to do is find the first letter in my price i.e. $140 and change the dollar to Rand so that it reads R140. This needs to happen even if it doesn't change to $, so if if it comes through as R, I want to be able to find that first letter and make it an R anyways. So that the price will always come out in Rands.

Hope this makes sense?

Thanks!

SixfootJames
  • 1,841
  • 5
  • 26
  • 42

3 Answers3

1

Try -

$(".price").each(function () {
    var currentText = $(this).text();
    $(this).text(currentText.replace("$","R"));
}); 

Working demo - http://jsfiddle.net/ipr101/bnsUR/1/

ipr101
  • 24,096
  • 8
  • 59
  • 61
0

$("#div_or_span_id").text( "R" + $("#div_or_span_id").text().substring(1) )

Blazemonger
  • 90,923
  • 26
  • 142
  • 180
-1
$target = $('span#target');
text = $target.text();

$target.text('R'+text.substring(1));

Will take everything but the first word, and prepend it with an 'R'.

jsFiddle Example

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
  • My little JS book says that `substr` is deprecated; `substring` or `slice` is preferred. – Blazemonger Aug 31 '11 at 13:06
  • I think your little JS book is the only one that says it's deprecated (since MDN shows no signs of this), but I'll take that as correct, corrected. – Madara's Ghost Aug 31 '11 at 13:09
  • "JavaScript: The Definitive Guide", 5th edition, O'Reilly, p.707. Also: http://stackoverflow.com/questions/1026069/capitalize-the-first-letter-of-string-in-javascript – Blazemonger Aug 31 '11 at 13:15