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

203
Vistas
¿Cómo se puede optimizar este código para que tenga menos líneas de código y sea más conciso?

Quiero hacer este código más corto. ¿Como un bucle o algo así? Sería genial si alguien me ayudara a acortar el código para poder agregar más nth-child. como nth-child:4, 5.

 $(document).ready(function(){ var src=$(".gallery-grid-item:nth-child(1) img").data("src"); $.ajax({ url:src, xhrFields:{ responseType:'blob' }, success:function(data){ var url=window.URL||window.webkitURL; $(".gallery-grid-item:nth-child(1) img").attr("src",url.createObjectURL(data)); } }); }); $(document).ready(function(){ var src=$(".gallery-grid-item:nth-child(2) img").data("src"); $.ajax({ url:src, xhrFields:{ responseType:'blob' }, success:function(data){ var url=window.URL||window.webkitURL; $(".gallery-grid-item:nth-child(2) img").attr("src",url.createObjectURL(data)); } }); }); $(document).ready(function(){ var src=$(".gallery-grid-item:nth-child(3) img").data("src"); $.ajax({ url:src, xhrFields:{ responseType:'blob' }, success:function(data){ var url=window.URL||window.webkitURL; $(".gallery-grid-item:nth-child(3) img").attr("src",url.createObjectURL(data)); } }); });
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

<script> $(document).ready(function(){ numberOfNthChilds = 5 for (let i = 1; i < numberOfNthChilds + 1; i++) { var src=$(".gallery-grid-item:nth-child(" + i + ") img").data("src"); $.ajax({ url:src, xhrFields:{ responseType:'blob' }, success:function(data){ var url=window.URL||window.webkitURL; $(".gallery-grid-item:nth-child(" + i + ") img").attr("src",url.createObjectURL(data)); } }); } }); </script>
about 4 years ago · Juan Pablo Isaza Denunciar

0

Prueba esto:

 <script> $(document).ready(function(){ for (var i = 1; i <= 3; i++) { var cls = ".gallery-grid-item:nth-child(" + i +") img"; var src=$(cls).data("src"); $.ajax({ url:src, xhrFields:{ responseType:'blob' }, success:function(data){ var url=window.URL||window.webkitURL; $(cls).attr("src",url.createObjectURL(data)); } }); } }); </script>
about 4 years ago · Juan Pablo Isaza Denunciar
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