Say I want to hide a div with id="foobar"
, but foobar does not exist yet, only after user clicks a button and make an ajax call, the div gets populated into the DOM.
How do I write a function that runs once the div comes into existence? The function cannot be brought by the ajax call. It must exist before the call.
I learned that something like this might help:
$(document).ready(function () {
$(document).on('click', '#futurebutton', function() {
alert("You clicked the future button");
});
but this seems to work only new button is clicked, what I need is having the function run once the div comes into existence.
so something similar to $(document).on( "COMES INTO EXISTENCE" , '#newdiv', function() ...
Thanks!