The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Waypoint find next div

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #190698


    Working on a function with waypoint.js that takes the current div in the viewport and finds the next one when clicking a button.

    Currently I’m getting a undefined value for the ‘next’. Not sure what could be wrong I guess the value can’t move from the waypoint function. Any help would be lovely.

    $(‘.wrap’).waypoint(function() {
    var next = $(this).next();

    $(“.button”).click(function() {
    $(“html, body”).animate({ scrollTop: next.offset().top }, 1000);


    Well you’ve got a scoping problem I’d say.

    Declaring var next =... inside a function sticks it into the scope of said function. That means it can’t be accessed outside of the function it was declared.

    What I’d do is return the value of next in the function so it can be passed as an object to another.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.