I found the same question, here
I am trying to dynamically create a button than can alert('...') in a Django template. However, for some reason my code is not working.
Here is the entirety of my sample.
{% block scripts %}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<script type="text/javascript">
$(function()
{
$('button').addClass('removeButton');
$("#addRowBtn").click(function()
{
$("#testP").after("<button class='removeButton'><b>x</b></button>");
});
$('.removeButton').live('click', function(){
alert('test');
});
});
</script>
{% endblock %}
{% block content %}
<div class="testArea">
<div class="inner"></div>
</div>
<p id="testP">test</p>
<form>
<table id="table">
<tbody>
<tr>
<td><button type="button" class="addRowBtn" id="addRowBtn"><b>+</b></button></td>
</tr>
</tbody>
</table>
</form>
{% endblock %}
thanks,