I am trying to use <template></template>
tags in my HTML to hold content that can then be displayed in the page. I am currently grabbing the template contents using html()
and writing them to the div using html()
. This all works as expected, but when the content is displayed in the div, things like button click events are not triggering. So the content seems to be out of scope. I assume this may be because it was loaded using html()
. Is there a better method I can use or is the problem caused by something else?
Example code
window.launcher = function(){
$('#launch').on('click', function(){
var content = $('#content').html();
$('#container').html(content);
});
};
window.launcher2 = function(){
$('#launch2').on('click', function(){
alert('You clicked me!');
});
};
The second function will not fire.
Edit: fixed typo