If there is a button loaded with ajax and you need to listen for clicks on it, use .on() as follows:
$(document).on('click', '.button', function(e) {
What I know, but I can not use the same logic with a scroll. I have an element called #overlayer that loads ajax, and then I try to listen to it scroll and run a function that adds a sticky class to the sidebar when it is about to exit the viewport:
$(document).on('scroll', '#overlayer', function() { stickySidebar(); console.log('scroll happened'); });
But it does not work.
I can get it to work as follows:
$('#overlayer').on('scroll', function() { stickySidebar(); console.log('scroll happened'); });
But it will not work with ajax content uploaded.
jquery scroll
any_h Mar 14 '15 at 16:23 2015-03-14 16:23
source share