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

297
Views
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 answers
Answer question

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 Report

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 Report

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 Report
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!