title: Button click not firing in modal window
body: <p>I'm using jQuery v3.6.0 and Bootstrap v5.0.2.  I have a dynamically generated modal which has buttons.  When the modal pops up, none of the buttons work and I cannot figure out why.</p>
  <p>Here's what I have tried:</p>
  <pre><code>$('#btnStayLoggedIn').click(function() {...});
  $('#btnStayLoggedIn').on('click', function() {...});
  $('#btnStayLoggedIn').delegate('click', function() {...});
  $('#btnStayLoggedIn').live('click', function() {...});
  </code></pre>
  <p>Basically, I have tried <a href="https://stackoverflow.com/questions/17455906/button-click-not-firing-in-modal-window-bootstrap">everything in this question</a>.  There are no errors in the console or anything.  It just will not fire.  Note: in jQuery 3.6.0, using live gives an error...</p>
  <p>Here's the code for the button:</p>
  <pre><code>&lt;button class=&quot;btn btn-default&quot; id=&quot;btnStayLoggedIn&quot;&gt;Stay Logged In&lt;/button&gt;
  </code></pre>
  <p>And here's the code for the handler:</p>
  <pre><code>// Called if the user clicks the Stay Logged In button.
  $(&quot;#btnStayLoggedIn&quot;).delegate('click', function() {
      console.log(&quot;execute 1&quot;); 
      if (typeof logoutTimer === 'object') {
          console.log(&quot;execute 2&quot;); 
          logoutTimer.stayLoggedIn();
      }
  });
  </code></pre>
  <p>The eventual handler is inside an object that has everything for the dialog that pops up when the timer expires.  On top of that, when I try to manually trigger the handler in the console, that doesn't work either.  I'm using this in the console:</p>
  <pre><code>$('#btnStayLoggedIn').click();
  </code></pre>
  <p>It just gives me some object to look at in the console:</p>
  <pre><code>jQuery.fn.init [button#btnLogout.btn.btn-default]
  </code></pre>
  <p>What I did find though, is that if I manually add an event handler to the button, then it will work:</p>
  <pre><code>btn1Obj = document.createElement(&quot;button&quot;);
  btn1Obj.classList.add(&quot;btn&quot;, &quot;btn-default&quot;);
  btn1Obj.setAttribute(&quot;id&quot;, &quot;btnStayLoggedIn&quot;);
  btn1Obj.innerText = &quot;Stay Logged In&quot;;
  btn1Obj.addEventListener(&quot;click&quot;, function() {
      this.stayLoggedIn();
  }.bind(this));
  </code></pre>
  <p>So why is this a problem with jQuery?</p>