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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:53:06+00:00 2026-06-13T12:53:06+00:00

I had working script based on id attribute. As I’m having many issues, decided

  • 0

I had working script based on id attribute. As I’m having many issues, decided to use class attribute with jQuery. But I’m not successful with the following script (I’m bad at scripting 🙁 )

It’ll be great if you expert can suggest me the better way. I have more than 300 words to replace with symbols (about 200 pages).

thanks a lot.

HTML code

 <script src="http://code.jquery.com/jquery-latest.js"></script>

 <input type="submit" name="replace" id="replace" value="Replace" />
 <div class="my_div">Default content</div>
 <div class="my_div">Default content 2</div>

java script

$('#replace').click(function() {
     var str=document.getElementByClassName("my_div").innerHTML;
     var n=str.replace("default","somesymbol");
     var n=str.replace("content","somesymbol");
     var n=str.replace("im","somesymbol");
     document.getElementByClassName("my_div").innerHTML=n;
    }
  • 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-13T12:53:07+00:00Added an answer on June 13, 2026 at 12:53 pm

    Using jQuery html() method if you use a function as it’s argument it will loop over the whole collection of elements with the class name , automatically give you access to the existing html and replace it if you return html string

    $('#replace').click(function() {
        $('.my_div').html(function( idx, oldHtml){
        /* if you need access to other properties or attributes of element -"this" or "$(this)" within this function*/
               return oldHtml.replace(/default|content|im/gi, 'somesymbol');
        });
    });
    

    Reference: http://api.jquery.com/html/

    Look down API page to section added in jQuery version 1.4

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

Sidebar

Related Questions

I'm having an issue with a simple PHP mailer. I've had this script working,
I had this working in prototype.js but it conflicted with a few script files.
My simple jQuery keypress script is not working. All i want to do is
I am trying to get this jGrowl working but I am not having any
I had working a java script in my html page.Now i moved the script
I am trying to get my session login script working and I had the
I'm working on an image resize script for php, and had a few questions..
I have a problem that I had working in a test but now in
I had a working Active Admin app working on my local server, but after
Perl newbie here...I had help with this working perl script with some HASH code

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.