How can I make .click() in jquery, but name of div id is in array (after calling .each() function)?
I have code like this:
<!DOCTYPE html>
<html>
<head>
  <title>Test website</title>
  <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
</head>
<body>
  <div id="first_div_id" class="div_class"><button type="button">Button no 1</button></div>
  <div id="second_div_id" class="div_class"><button type="button">Button no 2</button></div>
  <script>
    var ArrayWithDivId = [];
    $(document).ready(function() {
      $('.div_class').each(function() {
        ArrayWithDivId.push(this.id); //Add div id to array
      });
    });
    $(ArrayWithDivId[0]).click(function() {
      alert("Button no 1 clicked");
    });
    $(ArrayWithDivId[1]).click(function() {
      alert("Button no 2 clicked");
    });
  </script>
</body>
</html>but there is something wrong with:
$(ArrayWithDivId[0]).click(function() {
    alert("Button no 1 clicked");
});
It can't display that alert.
How to fix it?
 
     
     
    