silver silver - 1 year ago 76
jQuery Question

$(this).addClass('why-you-no-working'); not working on waypoint?

I just tried way points today as it looks awesome,

However, I'm having a hard time trying to make things work,

first simple test, works perfectly,

$('.parallax').waypoint(function() {
alert('I work');

But when i use $(this), it wont work, e.g.

$('.parallax').waypoint(function() {

you can see the sample from here ->

the second box should have black background color instead of blue, but for some reason its simple doesn't work,

if I use something like below, it works fine though, its

$('.parallax').waypoint(function() {

Spent almost three hours trying to get it working, but no luck,

Please help :)

Answer Source

In this case this does not refer to DOMElement. You can get reference to DOMElement, inside callback, through property this.element

$('.parallax:nth-of-type(2)').waypoint(function() {        
},{offset: '1%'}); 


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download