Scroll listener on body

user1297783 picture user1297783 · Sep 20, 2014 · Viewed 27.9k times · Source

I would like to ask about scroll listener. I want to add scroll listener on body but it seems doesnt work.

$('body').scroll(function(){
  console.log('SCROLL BODY');
});

I create basic example on fiddle, can someone explain me why it doesn't to work? Sorry for nubies question...

Answer

Lorenzo Marcon picture Lorenzo Marcon · Sep 20, 2014

Try with:

$(window).scroll(function(){
  console.log('SCROLL BODY');
});

This should be supported by all browsers.