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

162
Views
div content on scrolled bottom html javascript

i want to ask about div content scroll listener (not page). so I have an html code where the appearance of the web design resembles a native application. what I want to do is how do I detect if the user has scrolled down the content div? not a page because my web page for him is only silent, but the one that moves in the div. my div code is something like this

<div class="product-list-item">
   //product card
   //product card
</div>

enter image description here

and when i scroll like this

enter image description here

I want to see other products using ajax when it reaches the bottom of the div, for now I still using the manual button to load other products.

I've used this code but it's not working.

<script>
$(window).scroll(function() {
      if($(window).scrollTop() == $(document).height() - $(window).height()) {
            // ajax call get data from server and append to the div
      }
  });
</script>

does anyone have a solution for this? Thank you in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Assuming you have this:

<div class="product-list-item" id="target">
   //product card
   //product card
</div>

You can use this script to check if you reached your target div:

<script>
        $(window).scroll(function() {
            if ($(this).scrollTop()+$(this).height() >= $('#target').position().top) {
                console.log('Target Reached');
            }
        });
    </script>

You can use this approach to only execute the code once , once it has reached the target div

<script>
        let isReached = false;
        $(window).scroll(function() {
            if ($(this).scrollTop()+$(this).height() >= $('#ftr').position().top && isReached == false) {
                isReached = true;
                //ajax call
            }
        });
    </script>
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!