0

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,

Community
  • 1
  • 1

1 Answers1

0

use .on() live is removed since 1.9 and you are using 1.10

$("#testP").on('click','.removeButton', function(){
    alert('test');
});
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111