SixfootJames SixfootJames - 1 month ago 6
HTML Question

Finding the first letter in a span or div using jQuery

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!

Answer

Try -

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

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

Comments