I use templates in script tags. In javascript "class" first i'm declaring all elements I will work with. And if some elements will be added from template - they wont work.
<script type="text/template" id="new">
<div id="el">Yo</div>
</script>
<div id="container">
<button id="go">Paste here</button>
</div>
var $el = $('#el'),
goBtn = $('#go'),
$container = $('#container'),
newTpl = $('#new');
goBtn.on('click', function(){
$container.html(newTpl.html());
alert($el.length); // return 0!
});
https://jsfiddle.net/0fat5htg/ So how to declare all possible elements before they are loaded?