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

  • Home
  • SEARCH
  • 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 548333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:04:05+00:00 2026-05-13T11:04:05+00:00

In the following code: $(document).ready(function() { var content = ; for (var i =

  • 0

In the following code:

$(document).ready(function() {
    var content = "";
    for (var i = 0; i < 1000; i++) {
        content += "<div>Testing...</div>";
    }
    $("#Load").click(function() {
        $("#MyDiv").empty();
        $("#MyDiv").append(content);
        return false;
    });
});

Load is a simple link and MyDiv is a simple div. In each major browser I tested this in, when I click on the link multiple times, I see the memory usage go up in Task Manager. In IE, it goes up slightly each time and stays up. In FF, it goes up each time, but once in a while comes down (I think this means that the memory is being reclaimed or garbage collected – a good sign). In Chrome, it goes up significantly each time and stays up.

First, is this code cleaning up the DOM correctly? If so, why does the memory usage increase with every click?

Note: I tried to make the example as simple as possible, but similar to the problem I am having in my app.

  • 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-13T11:04:05+00:00Added an answer on May 13, 2026 at 11:04 am

    Wrap it around a div tag. It will help immensely and use native innerHTML (its faster).

    $(document).ready(function() { 
        var content = ""; 
        for (var i = 0; i < 1000; i++) { 
            content += "<div>Testing...</div>"; 
        } 
        $("#Load").click(function() { 
            document.getElementById('MyDiv').innerHTML = ('<div>'+content+'</div>'); 
            return false; 
        }); 
    }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: $(document).ready(function() { $(body).append(<div class='outer'><span class='inner'>Click me</span></div>); $(html).click(function(event) { var targetClass
i can reference link with specific id with following code $(document).ready(function(){ $(a#example_link_id).click(function(event){ var url
I'm using the following code.. $(document).ready(function(){ $(#test a).click(function(){ var labelTo = $(this).text(); window.location =
I am having problems with the following code $(document).ready(function() { var $selection = $('<div
I have the following code: $(document).ready(function() { var id = 'cbx'; var idPrefix =
I have the following JQuery code: $(document).ready(function () { var $containerHeight = $(window).height(); if
I got the following code : <script type=text/javascript> jQuery(document).ready(function(){ var Opened = false; jQuery('.expend-schedule').click(function(e){
I have the following JQuery code: <script type=text/javascript> $(document).ready(function () { var $containerHeight =
I have the following code $(document).ready(function() { $('a#slick-toggle').click(function() { $('#slickbox0').toggle(400); return false; }); });
I use the following code to collapse/show divs in my content page: $(document).ready(function() {

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.