showing results for - "document on click not working"
Herbert
24 May 2019
1$(document).ready(function() {
2    // This WILL work because we are listening on the 'document', 
3    // for a click on an element with an ID of #test-element
4    $(document).on("click","#test-element",function() {
5        alert("click bound to document listening for #test-element");
6    });
7
8    // This will NOT work because there is no '#test-element' ... yet
9    $("#test-element").on("click",function() {
10        alert("click bound directly to #test-element");
11    });
12
13    // Create the dynamic element '#test-element'
14    $('body').append('<div id="test-element">Click mee</div>');
15});
16