Search code examples
javascriptjqueryjquery-waypoints

jQuery $(this) returning [object Object]


I am trying to add a class to the same element when Waypoint is triggered. I only want the class to the element when that specific element triggers hence I want to use $(this).

Jquery:

var $waypointAppear = $('.waypoint-appear');
    $waypointAppear.waypoint(function () {
      $(this).addClass('show');
    }, { offset: '70%' });

HTML:

<div class="panel__text-box waypoint-appear">
<h2>Heading</h2>
<p>Text</p>
</div>

When it's triggered it doesn't append the class and returns [object Object].

Any help would be much appreciated. Thanks.


Solution

  • Please see this jsfiddle.

     $(this.element).addClass('show');
    

    You might find your answer.