Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7488635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:00:14+00:00 2026-05-29T15:00:14+00:00

Does anyone know how to do replace multiple text by clicking a button with

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:00:16+00:00Added an answer on May 29, 2026 at 3:00 pm

    Case 1: Controlled Input

    Assuming you can at least wrap all monetary values with something like this:

    <span class="money-value">£200.00</span>
    <span class="money-value">£300.50</span>
    

    And that you can add button declared with:

    <button id="secret-button">hide</button>
    

    Then you could have some jQuery code doing this:

    /**
     * Simple search and replace version.
     */
    $(function() {
      $("#secret-button").click(function() {
        $(".money-value").html($(".money-value").html().replace(/[0-9]/g,"X"));
      });
    });​
    

    or a more advanced one with:

    /**
     * Complet version.
     *
     * 1) on button click, if asking to hide:
     * 1.1) iterate over all entries, save their text, and replace it with markers
     * 1.2) toggle the button's text to "show"
     * 2) on button click, if asking to show:
     * 2.1) iterate over all entries, restore previous text
     * 2.2) clear the hidden store
     * 2.3) toggle the button's text to "hide"
     */
    $(function() {
      var hiddenStore = [];
    
      $("#secret-button").click(function() {
          if ($(this).html() == "hide") {
            $(".money-value").each(function () {
               var text = $(this).html();
    
               hiddenStore.push(text);
               $(this).html(text.replace(/[0-9]/g,"X"));
            });
            $(this).html("show");
          } else {
            $(".money-value").each(function (i) {
               var text = hiddenStore[i];
    
               $(this).html(text);
            });
            hiddenStore = [];
            $(this).html("hide");          
          }
      });
    });​
    

    Complete solution is here: See here: http://jsfiddle.net/u79FV/

    Notes:

    • this won’t work for input field values
    • this assumes your text entries have been marked as shown above
    • Does what you want with the button’s changing state.
    • Saves the values and puts them back.
    • Meant to work even if new fields are added dynamically.
    • Shankar Sangoli‘s answer uses a different way of saving the stored data, which you could as well consider (using the jQuery .data() method).
    • you may want to switch the button to an <input type="button" /> tag, in which case you’d use .val() instead of .html() to toggle its text.

    Case 2: Uncontrolled Input

    Assuming you don’t have control over where the values may show up, then you need to do something a bit more complicated, which is to look in the whole page for something that would look like a currency format. I’d advise against it.

    But, the jQuery Highlight plugin could be something to look at, as its code does something similar (in that it searches for pieces of code to modify), and you could then reuse some of solution 1 to make it fit your purpose.

    That would be harder to design in a fool-proof fashion though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In TextMate, does anyone know how you find & replace selected text?
Does anyone know of a script that can select all text references to URLs
Does anyone know why this jquery might not work? Ultimately I will replace the
Does anyone know of a good Command Prompt replacement? I've tried bash/Cygwin, but that
Does anyone know of any existing packages or libraries that can be used to
Does anyone know a good Java lib that will hook into SVN so I
Does anyone know how can I replace the comment_author_url field from all comments by
Does anyone know of a way of indexing regular expressions , so that I
Does anyone know any cool text editing program for easy code translation? I have
Does anyone know how can I replace onmousedown value with javascript? for example: <input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.