0

I want to check if scroll event was bound to window element in jquery. Basically I want to see if someone has done something like this:

$(window).scroll(function() { ... });

After looking for a little bit on SO, I have found more common question like if event already exist on an element with a working solution.

But when I tried to use $.data( $(window).get(0), 'events' ) I get undefined. Similar solution is proposed here as well.

So what is the correct way to check for scroll event?

Community
  • 1
  • 1
Salvador Dali
  • 199,541
  • 138
  • 677
  • 738

1 Answers1

2

I guess this is what you want:

$._data(window).events.scroll

That return undefined if there is no such event was binded to the window object

Example:

JSFiddle

alert($._data(window).events.scroll); // Should return 'undefined'

$(window).scroll(function() {
    alert('a');
});

alert($._data(window).events.scroll); // Should return 1 object

$(window).scroll(function() {
    alert('b');
});

alert($._data(window).events.scroll); // Should return 2 objects
Tony Dinh
  • 6,538
  • 4
  • 38
  • 57