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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:17:29+00:00 2026-06-18T12:17:29+00:00

I have the following on an HTML page: <script type=text/javascript> setInterval(function(){refresh()},5000); function refresh() {

  • 0

I have the following on an HTML page:

<script type="text/javascript">
setInterval(function(){refresh()},5000);
function refresh()
{
    $.post("test.php",
    {
           // nothing here             
    },
    function(data, textStatus)
    {      

      $('' + data + '').find('.maindiv').each(function () {
      $('.maindiv').replaceWith('.maindiv');
      });

    });  
}
</script>

<div id = "1" class= "maindiv">
<div sid= "1" class= "subdiv">old sub div content</div>
<div cid= "1" class= "childdiv">another old sub div</div>
<img id = "1" src="http://foo.com/bar.png"/>  
</div>

<div id = "2" class= "maindiv">
<div sid= "2" class= "subdiv">this content is old</div>
<div cid= "2" class= "childdiv">please update me!</div>
<img id= "2" src="http://foo.com/bar.png"/>  
</div> 

The PHP page that gets called to update elements (test.php):

<?php

 echo '<div id = "1" class= "maindiv">
       <div sid= "1" class= "subdiv">this is new sub div</div>
       <div cid= "1" class= "childdiv">this is also new sub div content</div>
       <img id= "1" src="http://foo.com/bar.png"/>  
       </div>'; 

 echo '<div id = "2" class= "maindiv">
       <div sid= "2" class= "subdiv">new content</div>
       <div cid= "2" class= "childdiv">new content for this child div</div>
       <img id= "2" src="http://foo.com/bar.png"/>  
       </div>'; 
?>

These 2 elements are also present on the HTML page. Basically what I want to call the PHP page and get those elements from the PHP page and loop through them in the response in the HTML page and replace each maindiv (including all its child elements) with the corresponding one on the HTML page.

This is just a very basic example. I do this because the content changes in these elements and want to replace the elemnts like live update.

The function I’m posting seems to have no response so don’t know how to achieve 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-06-18T12:17:30+00:00Added an answer on June 18, 2026 at 12:17 pm

    You need to index the maindiv elements in page so that they match with the new elements.

    Also need to modify what you are replacing with

     $(data ).filter('.maindiv').each(function (index) {/* filter or find depends on html structure sent*/
          /* "this" is the current div in response*/          
          $('#'+this.id).replaceWith(this);
    });
    

    each will track index, eq() is used to match same index in page.

    EDIT: Also change find() to filter() if only output is the DIV’s in root of output

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

Sidebar

Related Questions

I have the following test ASPX page: <head runat=server> <title></title> <script src=js/jquery-1.2.6.min.js type=text/javascript></script> <script
I have the following code: JS <script type=text/javascript> $(function(){ $('#fgotpwfield').hide(); $('#login_submit').click(function() { $('#form_result').fadeOut('fast'); $('#myccrxlogin
I have the following: <script type=text/javascript> $(document).ready(function () { $(input[id^='Position_'], select[id^='Level_'], input[id^='Title_'], select[id^='Status_'],).change(function (e)
I have the following file file: <html> <head> <title></title> <script type=text/javascript src=/Prototype.js></script> <script type=text/javascript>
I have the following jquery code in my view <script type=text/javascript> $(document).ready(function () {
I have the following CSS on my HTML page: <style type=text/css> .hidden {display:none;} .visible
I have the following HTML on a Jquery Mobile Page: <div data-role=controlgroup data-type=horizontal class=panelSwitcher>
I have the following HTML on my web page: <input id=htmlEdit type=checkbox/> Once the
I'm attempting to select all <script type=text/html> tags in a page. I use <script>
I have the following file: <html> <head> <title></title> <link rel=css type=text/css href=/empty.css title=css />

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.