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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:19:10+00:00 2026-06-13T11:19:10+00:00

I have the following script works for the replace with jQuery in innerHTML. HTML

  • 0

I have the following script works for the replace with jQuery in innerHTML.

HTML code

<input type="submit" name="replace" id="replace" value="Replace" />

<div class="my_div">Default1 content1</div>
<div class="my_div">Default2 content2</div>

java script

$('#replace').click(function() {
   $('.my_div').html(function( idx, oldHtml){
      return oldHtml.replace(/Default1|content1|Default2|content2/gi, 'symbol1');
   });
});

But I couldn’t modify the script for multiple unique replacement. Example I want to replace

Default1 to symbol1

Default2 to symbol2

content1 to symbol3

content2 to symbol4

the following doesn’t work

$('#replace').click(function() {
   $('.my_div').html(function( idx, oldHtml){
      return oldHtml.replace(/Default1/gi, 'symbol1');
      return oldHtml.replace(/Default2/gi, 'symbol2');
      return oldHtml.replace(/content1/gi, 'symbol3');
      return oldHtml.replace(/content2/gi, 'symbol4');
   });
});

Also I had early script based on id attribute, which is more than 500 replace lines. Is it possible that I can include similar structure in this new jQuery class attribute?

var str=document.getElementById("my_id").innerHTML;
var n=str.replace("Default1","symbol1");
var n=str.replace("Default2","symbol2");
document.getElementById("my_id").innerHTML=n;
}

Thanks a lot, you guys helped me a lot. 🙂

  • 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-06-13T11:19:12+00:00Added an answer on June 13, 2026 at 11:19 am

    Question 1 :

    Replace

    return oldHtml.replace(/Default1/gi, 'symbol1');
    return oldHtml.replace(/Default2/gi, 'symbol2');
    return oldHtml.replace(/content1/gi, 'symbol3');
    return oldHtml.replace(/content2/gi, 'symbol4');
    

    with

    return oldHtml.replace(/Default1/gi, 'symbol1')
        .replace(/Default2/gi, 'symbol2')
        .replace(/content1/gi, 'symbol3')
        .replace(/content2/gi, 'symbol4');
    

    Question 2 :

    Replace

    var str=document.getElementById("my_id").innerHTML;
    var n=str.replace("Default1","symbol1");
    var n=str.replace("Default2","symbol2");
    document.getElementById("my_id").innerHTML=n;
    

    with

    var $div = $('#my_id');
    $div.html(
        $div.html().replace("Default1","symbol1")
        .replace("Default2","symbol2")
    );
    

    (if you use jQuery, no need for those getElementById)

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

Sidebar

Related Questions

I have the following chunk of code. It works perfectly. <div id=restaurant_locations></div> <script type=text/javascript>
I have the following code that works fine in IE: <HTML> <BODY> <script language=JavaScript>
I have the following code select box div: Make:<br> <select name=Make> <option value =
I have the following jQuery code: <script type=text/javascript> jQuery.noConflict(); jQuery(document).ready(function(){ jQuery('a.connect').bind(click, function(event) { var
I have the following script that works well in Firefox and Chrome (not sure
Following script works well without having special character. Unfortunately, I have full of special
I am using latest Jquery and the following script: <script type=text/javascript> $(document).ready(function(){ var el
I have following JS code (stripped to minimal size where problem still exists) <html>
hello i have following code and it works fine for finding and replacing string...
I have the following script which works fine locally: <?php //Report all errors error_reporting(E_ALL);

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.