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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:32:36+00:00 2026-05-30T14:32:36+00:00

On site: http://jonirautiainen.net/code_edit/ there on left is a panel which has a filetree. .load(‘scandDir.php’)

  • 0

On site: http://jonirautiainen.net/code_edit/ there on left is a panel which has a filetree.

.load(‘scandDir.php’) loads new <ul><li></li></ul> elements from php-file.

The problem is that because this script is a loop it executes loadNew(); multiple times.
Please check the problem live on page mentioned before. Click on those folders to open them and you will see those files showing up multiple times.

Script needs to be looped because .load is asynchronous. $(".file-tree a").on( won’t let me select those new elements created by executing .load.

Is there any other way to do this?

    function loadNew()
    {
        $(".file-tree a").on("click",function ()
        {
                var path = $(this).attr("title");
                var folder = $(this).text();
                var name = $(this).attr("name");
                var id = $(this).parent().attr("id");
                $("#testi").html(path + folder + name + id);
                var liHtml = $(this).parent().html();               
                    if(liHtml.match(/<ul /))
                    {           

                    }else
                    {
                        if(name=="dir")
                        {
                            $("#hiddenDiv1").load("scanDir.php?path=" + path + "/" + folder, function() {
                              var hiddenDiv = $("#hiddenDiv1").html();
                                $("#" + id).append(hiddenDiv); 
                                loadNew();
                            });
                        }
                    }

        });
    }
    loadNew();
  • 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-30T14:32:37+00:00Added an answer on May 30, 2026 at 2:32 pm

    You keep piling on new click handlers. I understand that you’re loading new elements and they need to have their events handled too, but in the process you’re adding more handlers to the existing elements. So after you expand several directories, the older elements will have a couple of handlers on them; and when you click those, all of those handlers will get invoked (which gets you additional elements).

    One approach is to take care what you add your click handler to. Only add it to the newly loaded elements.

    Another, easier approach is to take advantage of the power of jQuery’s on() method. If you write it like this:

    $('#fileNavi').on('click', '.file-tree a', function() {
      ...
    });
    

    and only once, the handler will work for current and any future elements that appear in your hierarchy. Then inside the handler just do the AJAX call and add the new data to the document, trusting jQuery to handle the events for you. Get rid of the loadNew function altogether, especially the deviant recursion you have going there.

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

Sidebar

Related Questions

the site: http://shawn.sc2broadcast.net/test/ the code: <?php $homepage = file_get_contents('http://www.macsiam.com/sites.php'); preg_match_all('%\'http://([^./]+).[^.]+\.[a-z]{2,4}\'%i', $homepage, $domains, PREG_PATTERN_ORDER); //
On this site: http://jumpthru.net/newsite/vision/ I am using CSS sprites for my navigation with PHP
There is site http://abc.com (made in PHP, MySQL, Apache, Linux environment). Currently, MySQL on
at this site: http://yoursdproperty.com/index.php?option=com_jumi&fileid=8&Itemid=34 you will see on the left there is a navigation
My Site: http://www.soskin.zxq.net/incorporate.php , http://www.soskin.zxq.net/estate.php If you look at these two pages you will
I recently deployed a site http://boardlite.com . One of the tester websites http://www.gidnetwork.com/tools/gzip-test.php suggests
for this site: http://yoursdproperty.com/ do you see how there some extra white space all
Our site http://m.sa2010.gov.za has a simple menu structure that relies on floating divs to
there's a site: http://joopz.com you can use a browser to send a receive text
I typically use the site http://www.pinvoke.net/ to grab a DllImport declaration whenever I need

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.