开发者

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开发者_如何学C the price will always come out in Rands.

Hope this makes sense?

Thanks!


Try -

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

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


$("#div_or_span_id").text( "R" + $("#div_or_span_id").text().substring(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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜