Search code examples
javascriptjqueryjquery-waypoints

waypoints.js get id from element


I try to use waypoints.js to update the url on a one page website. The waypoints event is firing correct but i cant get the id out of the section i scrolled to. The variable is always undefined.

$('section').waypoint(function() {
    var hash = $(this).attr('id');

    window.location.hash = (hash);
    currentHash = hash;
});

Solution

  • I solved it. You should use the this of waypoints.js:

    $('section').waypoint(function() {
        var hash = this.element.id
    
        window.location.hash = (hash);
        currentHash = hash;
    });