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

  • Home
  • SEARCH
  • 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 3430532
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:12:57+00:00 2026-05-18T07:12:57+00:00

I know this is something that is fairly well documented, but I’m having some

  • 0

I know this is something that is fairly well documented, but I’m having some serious trouble applying any of it to this situation.

I need to come up with a way of essentially saying: If ‘phone number’ appears on page -> randomly replace it with either image1, image2 or image3. And I need it to happen five times with one of three possible images to be displayed in place of each of the 5 different ‘phone number’.

Originally I considered starting by creating 2 separate arrays. One array for the phone numbers and one array for the images to replace it, but I was completely stumped as to how I could randomly apply one of three images to a single array element.

Any ideas or inspiration is very much appreciated.

  • 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-18T07:12:58+00:00Added an answer on May 18, 2026 at 7:12 am

    The main bind I should think will be locating the phone numbers, unless you convert the whole page in to HTML code, and place it all back in, that would not be ideal.

    You can keep a list of phone-number/image pairings together by making either two arrays that share the same indexing, or an array of tuples (just an object with two entries).

    var phoneReplacements = [
                              { 'phone': '01234 567890', 'image': 'phone-support.jpg' },
                              { 'phone': '01234 000000', 'image': 'phone-customer.jpg' },
                              { 'phone': '01234 999999', 'image': 'phone-technical.jpg' }
                            ];
    

    Then you can loop through them finding and replacing.

    for (replacementIndex in phoneReplacements) {
        var cPhoneNumber = phoneReplacements[replacementIndex]['phone'];
        var cImageSrc = phoneReplacements[replacementIndex]['image'];
    
        /* find all elements containing phone number text and loop */
    
        /* get content as HTML */
        var cContent = cElement.innerHTML;
    
        /* replace text with image */
        var cNewContent = cContent.replace("/" + cPhoneNumber + "/g", '<img src="' + cImageSrc + '" alt="' + cPhoneNumber + '" />');
    
        /* set new content */
        cElement.innerHTML = cNewContent;
    
        /* repeat for all matching elements */
    }
    

    Using jQuery would make things a bit easier, the trick is finding the phone numbers, which basically means searching all text nodes on the page.

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

Sidebar

Related Questions

This is something that I'm sure I should know the answer to, but either
I thought this would be something that's fairly common - but cant find it
This is something that's I've wanted to know recently, mostly out of curiousity. I'm
I know this is going to be something simple that I'm just missing somehow,
I know that if I do something like this: class Obj { public: int*
I know this isn't strictly speaking a programming question but something I always hear
This is something stupid I probably should know, but Googling fails me: When compiling
This is something I encounter frequently, but I don't know the elegant way of
I don't know if this is a well known 'thing' or something new in
I feel like this is something I should already know, but I'm just not

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.