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);
}

```
```
$('#yourButton').click(function(){
    var saveText = $('body').text();

    $(this).data('oldText', saveText);

    if ($(this).text() == "Hide"){
        $('body').text($('body').text().replace(/\d{1}/, "X"));
        $(this).text('Show');
    }
    else{
        $('body').text($(this).data('oldText'));
        $(this).text('Hide');
    }
});

```

This is kind of a complicated problem actually. You will need to be able to save the state of the text when its in number form so you will be able to toggle back and forth. The above code is untested but hopefully it will give you an idea what you need to do.