Reputation: 131
I have my template in a separate file from the rest of the js code. I'm trying to do eventhandlers for my template (for example my onclick event below), but it doesn't work. Can anybody tell me how I can solve this?
var output = _.template($('#myTemplate').html(), {myData});
$('#content').html(output);
//This doesn't work
$('#myButton').click(function(){
//Do something
});
//My template
<script type="text/template" id="myTemplate">
<h2><%= myTitle %></h2>
<button id="myButton">Button</button>
</script>
Upvotes: 2
Views: 2120
Reputation: 14225
$('#myButton').live('click', function(){
//Do something
});
Upvotes: 2