Question: Does anyone know how to do replace multiple text by clicking a button with jQuery?

I've built a website that displays some text/data eg; "£100.00", but I what I need is to be able to 'replace' those monetary values with "£XXX.XX" with a **'Hide' button** like you get on some banking websites. For example one web page has:

£100.00, £200.00, £130.00 etc etc..

...so when a user presses the Hide button, all of the numbers on the page turn to £XXX.XX. Ideally, the button should then display "Show" instead of "Hide" and switch back when toggled.

This is for a static dummy site, so no data base.

I suspect this is best handled with jQuery?

Thanks for your time,

D.

Answer: 
You could use a regular expression:

```
var expression = /\d{1}/g;
var newString = myString.replace(expression,"X");

```

Then just dump `newString` into whatever control you need it to appear in.

**Edit:**  

A jQuery idea for something like this would be to give all of the controls that have these numbers a common class identifier to make them easy to grab with the selector:

```
$(".numbers").each(function() {
    $(this).text($(this).text().replace(/\d{1}/g, "X"));
}

```

... more readable ...

```
$(".numbers").each(function() {
    var text = $(this).text();
    var newText = text.replace(/\d{1}/g, "X");
    $(this).text(newText);
}

```
```
function toggleMoney() {
    $('.money').each(function() {
        var $$ = $(this), t = $$.text();
        $$.text($$.data('t') || t.replace(/\d/g, 'X')).data('t', t);
    });
    $('#toggleButton').text($('.money').text().match(/\d/) ? 'hide' : 'show');
}

```

<http://jsfiddle.net/DF88B/2/>