waypoints
waypoints copied to clipboard
$(this) not working with waypoints
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
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.
To simplify things for anyone who happens upon this page, that means to use $(this.element) instead of $(this) inside of a handler function.