Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Waypoints - No element option passed to Waypoint constructor

I am using waypoints in my rails project. (using gem waypoints_rails)

Waypoints is working fine on the page I want it to work on. The elements I am using waypoints with only exist on this page. I am using Waypoint Inview.

var inview = new Waypoint.Inview({
  element: $('#the-element')[0],
  entered: function(direction) { 
     console.log("working");        
  }
});

This is working correctly.

However, my home page is now giving this error :

 Uncaught Error: No element option passed to Waypoint constructor

Any help ?

like image 732
smanvi12 Avatar asked Oct 26 '16 02:10

smanvi12


1 Answers

I had the same problem. Try wrapping your waypoint in a conditional to check if the element exists on the page.

if ( $( "#the-element" ).length ) {
    var inview = new Waypoint.Inview({
        element: $('#the-element')[0],
        entered: function(direction) { 
           console.log("working");        
        }
    });

}
like image 169
Garet H. Avatar answered Nov 03 '22 19:11

Garet H.