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 4234894
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:25:16+00:00 2026-05-21T02:25:16+00:00

Thanks in advance for the help. I have been fooling around with browser extensions

  • 0

Thanks in advance for the help.

I have been fooling around with browser extensions (a novice) and I have been trying to figure out some word swapping issues; specifically, I am trying to do something akin to a rebus.

I tested my code out on just a plain text page, and it works. But then, when making it an extension, it basically loses the styling on the page and turns it into text only.

I have been looking for a more unobtrusive way to swap a word like “shoe” with an image of a shoe. I have been working in jQuery and using the documentation to make what I already did below.

$(document).ready(function () {
    var newText = $("body").text().split(" "); 
    $.each(newText, function(index, value) {
        if (newText[index] === "shoe") {
            newText[index] = "<img src='http://.../shoe.png' alt='shoe'>";
        }
    });
    var altText = newText.join("</span> <span>");
    $("body").html(altText);
});

I see what I am doing: ripping the text out and then shoving back in. But I am at a loss of what I should use.

I am aware of the replaceWith() function and I suppose that is the right one to use. But how do I get to the “shoe” words in the first place?

Thanks

  • 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-21T02:25:17+00:00Added an answer on May 21, 2026 at 2:25 am

    I don’t know if jQuery helps a lot here. You are best off probably just doing a replace on the full html… with some (potentially bad) notes and caveats.

    1) Ideally, you would only use text() via jQuery, but after you have the text, you have no easy way of putting it back. this is <span>my</span> dog => this is my <img src="dog.jpg">.. losing your span.

    2) Replacing on the full html would be bad if your html tags contain the words you are replacing!! <div id="dog"> => <div id="<img src="dog.jpg">"> Ugh!

    3) Use word boundary delimiters \bshoe\b in your regular expression to match on whole words only to prevent: catastrophe => <img src="cat.jpg">astrophe

    Example:
    http://jsfiddle.net/jtbowden/7cajW/

    BETTER:

    I coded a better solution, using lower-level code based on jquery.highlight.

    http://jsfiddle.net/jtbowden/jRebk/3/

    It adds a function prototype for .rebus(wordMap, [caseSensitive], [useWordBoundaries]), where the defaults are false and true, respectively, for the latter two.

    Usage:

    var myRebus = {
        "shoe": "http://i54.tinypic.com/254zjgy.png",
        "hat" : "http://i55.tinypic.com/11iicgg.png",
        "dog" : "http://i55.tinypic.com/287p11k.png",
    };
    
    $('body').rebus(myRebus);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

and thanks in advance for any help. I have been dabbling in this code
I have a query I need some help with, have been checking out a
Hi everyone and thanks in advance for the help. So I have been learning
I have been having trouble trying to figure out how to properly convert the
I have been trying to figure this out for a friend. They have an
newbie here, so thanks in advance for help! I have a Wordpress site with
Thanks in advance for your help. I have a need within an application to
I am using c# .net. Thanks in advance for any help. I have searched
Thanks for any help in advance, I can't wrap my SQL skills around this
I'm just starting to teach myself Objective C and have been fooling around with

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.