Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda