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

299
Vistas
How to offset().top from every $('.example p') element

I'm trying to get every offset().top value of every $('.example p') element

console.log($('.example p')[1].offset().top)

Uncaught TypeError: $(...)[1].offset is not a function

I've tried a bunch of things, like using other selectors, using a for loop, foreach... I can only get the offset().top value from the first element of that array by removing [1], for the second, third, etc... element I can't seem to get it.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Because $('.example p')[1] return node HTML (element html)

If you want to get offset with jquery you can use : $('.example p').eq(1).offset()

about 4 years ago · Juan Pablo Isaza Denunciar

0

Simply iterate through each of the elements in the selector ".example p" using each

See demo:

$(".example p").each(function(i)
{
  console.log( $(this).offset().top); 
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="example">
  <p>Doggo ipsum you are doing me a frighten corgo heckin good boys and girls pupperino, fat boi. Doing me a frighten you are doing me the shock clouds you are doin me a concern borkf super chub, wow very biscit you are doing me a frighten pupper.   you are doing me a frighten pupper porgo. Fluffer wow very biscit blop fluffer puggorino puggo very hand that feed shibe, boofers maximum borkdrive the neighborhood pupper boofers. 
  </p>

  <p>Doggo ipsum you are doing me a frighten corgo heckin good boys and girls pupperino, fat boi. Doing me a frighten you are doing me the shock clouds you are doin me a concern borkf super chub, wow very biscit you are doing me a frighten pupper.   you are doing me a frighten pupper porgo. Fluffer wow very biscit blop fluffer puggorino puggo very hand that feed shibe, boofers maximum borkdrive the neighborhood pupper boofers. 
  </p>
</div>
<div class="something">
  <p>Doggo ipsum you are doing me a frighten corgo heckin good boys and girls pupperino, fat boi. Doing me a frighten you are doing me the shock clouds you are doin me a concern borkf super chub, wow very biscit you are doing me a frighten pupper.   you are doing me a frighten pupper porgo. Fluffer wow very biscit blop fluffer puggorino puggo very hand that feed shibe, boofers maximum borkdrive the neighborhood pupper boofers. 
  </p>

  <p>Doggo ipsum you are doing me a frighten corgo heckin good boys and girls pupperino, fat boi. Doing me a frighten you are doing me the shock clouds you are doin me a concern borkf super chub, wow very biscit you are doing me a frighten pupper.   you are doing me a frighten pupper porgo. Fluffer wow very biscit blop fluffer puggorino puggo very hand that feed shibe, boofers maximum borkdrive the neighborhood pupper boofers. 
  </p>
</div>
<div class="example">
  <p>Doggo ipsum you are doing me a frighten corgo heckin good boys and girls pupperino, fat boi. Doing me a frighten you are doing me the shock clouds you are doin me a concern borkf super chub, wow very biscit you are doing me a frighten pupper.   you are doing me a frighten pupper porgo. Fluffer wow very biscit blop fluffer puggorino puggo very hand that feed shibe, boofers maximum borkdrive the neighborhood pupper boofers. 
  </p>

  <p>Doggo ipsum you are doing me a frighten corgo heckin good boys and girls pupperino, fat boi. Doing me a frighten you are doing me the shock clouds you are doin me a concern borkf super chub, wow very biscit you are doing me a frighten pupper.   you are doing me a frighten pupper porgo. Fluffer wow very biscit blop fluffer puggorino puggo very hand that feed shibe, boofers maximum borkdrive the neighborhood pupper boofers. 
  </p>
</div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

It's seem that jQuery don't return an array of jQuery object. Check for example if $('.example p')[1] is a jQuery object. You should convert all items in jQuery object like this:

var allExample = $('.example p').map((i, e) => $(e))

And then retry:

console.log(allExample[1].offset())
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