I have a button which is added dynamically
    <button id="btnSubmit">Button 1</button>
    $(document).ready(function(){
    $('#btnSubmit').on('click', function(){
        alert('Button 1');
        var button2 = '<button id="btn2" >Button 2</button>';
        $('#btnSubmit').after('<p></p>' + button2);
    });
    $(document).on('#btn2', 'click', function(){
        alert('Button2 clicked');
    });
  });
Now, when I click on #btn2 the event is not detected. How can this be fixed?
 
     
    