Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
Jquery load a fragment of external file (n divs)

I'm trying to load contents of an external file into master html piece by piece. I managed to load the first part, but I don't know how to select the next one. Ideally, the next part is loaded on scroll (when one hits the bottom of the page) - scroll function works for me too, so the only problem is how to select the next fragment of external html.

My master template:

<div id='master'> 
  // This is where to load external divs
</div>

External file has all the divs I want to load:

<div cls='new'> </div>
<div cls='new'> </div>
<div cls='new'> </div>
...

I started with loading the first 10 elements into my empty master template (this works) and then try to load the next 10 elements in loop using gt selector (this is my last idea for this problem, but not working):

$(document).ready(function () {
  x = 10;
  $('#master').load('external.html .new:lt('+x+')',function() {

    var size_master = $("#master .new").length;
    master = document.getElementById('master');

    y = size_master + 1; // current number of divs on master template +1
    z = y+10; // append y by the next 10 divs from external.html

    master.onscroll = function() {
      if(master.scrollTop + master.clientHeight == master.scrollHeight) {
      for (var i = y; i < z; i++) {  
        $('#master').last().load('external.html .new:gt('+i+')');
      };
      };
    };
  });
});

I don't want to load the whole external file at the beginning as it is huge and loading it gradually is supposed to make the web work smoothly.

I was also thinking of using slice(start,end) function on external.html to select the next part of divs to load but I can't make it work.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!