[Solved] JS selector on click not working for django model generated content [duplicate]

Your first code will also work if the element you reference is part of the document at that time, so make sure to put the script near the end of the document, or else wrap it in the ready handler: $(function () { $(‘#delete-btn’).on(‘click’, function(){ return confirm(‘Are you sure you want to delete this?’); }); … Read more