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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:02:19+00:00 2026-05-31T02:02:19+00:00

Im trying to replace the html of emoticon (the image) in to plain text.

  • 0

Im trying to replace the html of emoticon (the image) in to plain text. But I need normal HTML to show.

On here: http://jsfiddle.net/xk2VX/

Im using:

$("code").each(function() {
    var a = ['<img class="smile" src="http://static.yamma.org/images/icons/smile.png">', '&lt;img class="laugh" src="http://static.yamma.org/images/icons/laugh.png"&gt;'],
        b = [":)", ":D"];

    for (var d = 0; d < a.length; d++) {
        var e = $(this).html(),
            f = e,
            g = f.indexOf(a[d]);
        while (g != -1) {
            f = f.replace(a[d], b[d]);
            g = f.indexOf(a[d]);
        }
        $(this).text(f);
    }
});​

And it returns: &lt;div&gt;Hi&lt;/div&gt; :) :D :) :D;
but it should return: <div>Hi</div> :) :D :) :D;

I just don’t get why the < and > are being replaced with &lt; and &gt;

Is there a fix for this? Thanks in advance.

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

    I notice that you’re calling .text() at the end of your for loop when you should be calling .html() instead, even though you correctly call .html() at the beginning:

        for (var d = 0; d < a.length; d++) {
            var e = $(this).html(),
                f = e,
                g = f.indexOf(a[d]);
            while (g != -1) {
                f = f.replace(a[d], b[d]);
                g = f.indexOf(a[d]);
            }
            $(this).text(f);
        }
    

    .text() always converts HTML special characters to entities so they won’t be treated as markup, because it expects text, not HTML.

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

Sidebar

Related Questions

Here's a fictional example of what i'm trying to replace http://ryanhollingsworth.com/test/map.html Goal: input a
I'm trying to replace a friendly url pattern with a html url notation but
I'm trying to replace a small part of text in a large HTML document
I have a string that represents an html document. I'm trying to replace text
I am trying to replace some div text automatically using the .html command in
I'm trying to replace all my empty select boxes with a text message but
I'm trying to replace text inside an HTML string with Javascript. The tricky part
I am trying to replace a <blockquote> tag with text in an HTMl document.
I am trying to find and replace html data using jquery. The jquery script
I am trying to replace all £ symbols in a HTML file with &pound;

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.