What is the best approach to apply JS to the dynamically loaded content. Let say I have this:
form.html (to load dynamically)
main.html with a button, when clicked DIV shown and form.html dynamically loaded.
In my main.html I have JS that suppose to find form tag (from a dynamically loaded form) and process it further (I use jQuery). I could have included that JS in form.html and then it works, but what I want to do is to have my JS in main.html and yet be able to manipulate dynamically loaded content with it. Can that be achieved? Thanks.
EDITED:
form.html
<form id="f"><input name="i"/></form>
main.html
<script>
$(document).ready(function() {
$('#b').on('click', function() {
$('#div').load('form.hmtl');
//Again, I know that I can pass JS code into load() call. I want to be able
//to avoid that.
});
var $form = $('#f');
$form.mask() //it's a jquery plugin that blocks mouse clicks on a specific element
//note that form is not yet loaded. I know that I can pack the code above into a
//function and pass it with .on('click', function(){}) call. The question is:
//is it possible to avoid that.
});
</script>
<button id="b">Load Form</button>
<div id="div"></div>