SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Huh? What now? tntcheats's Avatar
    Join Date
    Aug 2003
    Location
    BC, Canada
    Posts
    719
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Erasing what's rendered thus far.

    How would I go about erasing what's been rendered?

    IE I have a for loop where I want to erase what it creates each time so that the next outputted thing in the loop replaces the already rendered thing on the page.

    Thanks.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,264
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    replacing rendered portions

    You can use javascript to replace page elements with a setTimeout. This can't be done with server-side PHP.

  3. #3
    Huh? What now? tntcheats's Avatar
    Join Date
    Aug 2003
    Location
    BC, Canada
    Posts
    719
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gah that's what I feared. Thanks.

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you mean rendering, do you mean each time the page is refreshed? Or using your setTimeout you want to clear the original contents?

    say you have this

    Code:
     <div id="dynContent"></div>
    now you populate that code using setTimeout

    Code:
     function Pop()
     {
        var dynContent = document.getElementById('dynContent');
        for(i = 0; i < 50; i++)
        {
     	   dynContent.innerHTML = dynContent.innerHTML + "<p>test" + i + "</p>";
        }
        setTimeout(Pop(), 5000);
     }
    using the above code, if you were to let that run, every 5 seconds it would populate 50 p tags and continue to run until either the page buffer dies or you change the page or close the browser.

    if you set the innerHTML to "" each time that function is called, this is resolved.

    Code:
      function Pop()
      {
         var dynContent = document.getElementById('dynContent');
        dynContent.innerHTML = "";
         for(i = 0; i < 50; i++)
         {
      	   dynContent.innerHTML = dynContent.innerHTML + "<p>test" + i + "</p>";
         }
         setTimeout(Pop(), 5000);
      }
    Does this help?

    Gav



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •