Reputation: 2440
I have this funny bug that occurs and I am at a loss as to how to debug it. Every time a page loads on my site a scroll event fires. The page doesn't visibly move, and i certainly am not triggering the scrolling via the mouse or keyboard. I know that scroll event is firing because i put a line of code that reads
$(window).bind('scroll', function (e) {console.log(e)});
Sure enough on every page i get a little "jQuery.Event" message in my console's log. When i break point it my call stack ends at jQuery.even.dispatch.apply(eventHandle.elem, arguments), which doesn't give me a ton to work with.
Here's the question. How do I find out what is triggering this scroll event? Is there an attribute in the jquery event object that will tell me if the scroll was user triggered or triggered by a script? In this situation what would you do to figure this out?
Upvotes: 14
Views: 4892
Reputation: 7654
Alright, it looks like jQuery hides all event binding data within a hidden attribute. This post describes ways that lets you find out at least what is being run -- it is still your responsibility to find out where the handlers are in which file.
In the case where scroll
events are involved:
var scrollHandlers = jQuery._data(window, 'events')['scroll'];
for (var i = 0; i < scrollHandlers.length; i++) {
console.error(scrollHandlers[i].handler); // or console.debug, whatever proves they exist
}
Upvotes: 2