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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:08:14+00:00 2026-05-21T16:08:14+00:00

I need to run a search and replace on HTML similar to the following…

  • 0

I need to run a search and replace on HTML similar to the following… I need to have “Find Next” “Replace” and “Replace All” options…. the trick is that I need to run an AJAX request to update the values in the database for each field once the value is replaced.

The only trouble I’m running into is that I”m unsure exactly how to search the contents of #sheet and replace the values with the new value the user has provided.

<div id='sheet'>
<div class='item' id='field-18583'>This is yet another test</div>
<div class='item' id='field-18585'>This is test data</div>
</div>

I should say that it’s possible I’ll have TONS of text to search, so ideally I’d only find the next instance of the item that’s being searched for, not all instances. So when I hit “Find Next”, if I”m 3 items in, it’ll go to the 4th.

What’s the best way in javascript to maintain the indexing on this without storing all found results in a variable and causing lag on the page?

  • 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-21T16:08:15+00:00Added an answer on May 21, 2026 at 4:08 pm

    I would build a data object while traversing matched elements. Then send the object so you do not have multiple ajax request from a loop. jsfiddle:

    <div class='item' id='field-18583'>This is yet another test</div>
    <div class='item' id='field-18585'>This is test data</div>
    

    Script:

    var searchTerm = 'This is',
        replaceWith = 'This is new',
        updateObj = {};
    $("#sheet div.item:contains('" + searchTerm + "')").each(function(){
       // use id to build an update object
        updateObj[this.id.replace('field-', '')] = {
            oldText: searchTerm, 
            newText: replaceWith
        }; // not sure what you are trying to save here
       // manipulate html
       this.innerHTML = this.innerHTML.replace(searchTerm, replaceWith);
    });
    // after, send ajax data `updateObj`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to find links in a part of some html code and replace
I have a query that will need to run 28 000 times in a
Hallo all. I need to run the ' replace([column], [new], [old]) ' in a
i need run code that will create a database and populate tables. i am
I need to run an equipment audit and to do that I need to
I need three fast-on-large-strings functions: fast search, fast search and replace, and fast count
I have a file that I need to reformat and remove extra blank lines.
I want to select all text and do a search and replace. I want
I need to do a search and replace on long text strings. I want
I have an html text fragment that's part of the page's DOM that I

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.