I'm trying to work out a way to delegate an event to future, dynamically loaded elements using .on
I have a button (#button) which is present when the DOM is loaded.
The new elements (let's give them a class of .newElement) are then loaded into the page dynamically.
I want to click on '#button' and scroll to '.newElement.'
Is this possible?
The following is where my head is at:
jQuery(document).on("click", '#button', function (e) {
jQuery(window).scrollTop(jQuery('.newElement').offset().top);
});
This doesn't work as #button can't find .newElement in the DOM.
Thanks