Is it possible to call jquery function when a new element has been added to the DOM?
With jquery .on()
I can do something like this:
<script type="text/javascript">
$(document).on("click", ".my-test", function() {
console.log('New element added!');
});
</script>
So when the element is clicked upon it'll write to the console - but can run this function as soon as it's added to the DOM?
I imagine it would look something like this..
<script type="text/javascript">
/* Just run when it's added... */
$(document).on(".my-test", function() {
console.log('New element added!');
});
</script>
How can I achieve this?