Event handlers on dynamically created elements? [duplicate]
问题 This question already has answers here : Event binding on dynamically created elements? (23 answers) Closed 2 years ago . $(document).ready(function () { $('.add-button').on('click', function () { $('.alert-button').after('<button type="button" class="alert-button">Click me! </button><br>'); }); $('.alert-button').on('click', function () { alert('HI!'); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button type='button' class="alert-button"