waypoints icon indicating copy to clipboard operation
waypoints copied to clipboard

$(this) not working with waypoints

Open avconsbn opened this issue 8 years ago • 2 comments

Hi,

jquery.waypoints.min.js 4.0.1, jquery.min.js 3.1.1 I'm trying to add a class to a waypoint element, but using $(this) doesn't work.

$('.paralax').waypoint(function() {
         console.log("hello")
         $(this).addClass('in-view');
      });

work

$('.paralax').waypoint(function() {
         console.log("hello")
         $('.paralax').addClass('in-view');
      });

How to solve? Thank you

avconsbn avatar Mar 21 '17 17:03 avconsbn

As you can read in the Getting started guide in the "this" chapter:

this?

When we're inside the handler function the this keyword is a reference to the Waypoint instance. We can use this object to access all the properties and methods in the API. One of the most useful properties is element, the waypoint's DOM element.

So you should use the available element variable.

As this is not an issue please close.

maartenvanbenthem avatar Mar 30 '17 08:03 maartenvanbenthem

To simplify things for anyone who happens upon this page, that means to use $(this.element) instead of $(this) inside of a handler function.

aaronldunlap avatar Mar 04 '18 07:03 aaronldunlap