title: How to retrieve button ids in tictactoe game in javascript
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var table = [];
      var blocks = 9;
      var player1, player2, boardId;
      var chance = 1;
      var buttonKey;
      winningCombinations = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 4, 7], [2, 5, 8], [3, 6, 9],
      [1, 5, 9], [3, 5, 7]];
  
      $(document).ready(function () {
  
          buttonId = 1;
  
          for (var index = 0; index &lt; blocks; index++) {
              buttonKey = document.createElement("button");
  
              if ((index == 3 || index == 6)) {
                  lineBreak = document.createElement('br');
                  document.body.appendChild(lineBreak);
              }
  
              buttonKey.innerHTML = " + ";
              buttonKey.id = buttonId;
              buttonKey.setAttribute("value", buttonId);
              buttonKey.setAttribute("text", buttonId);
  
              buttonKey.style.fontFamily = "Times New Roman";
              buttonKey.style.backgroundSize = "50px";
              buttonKey.style.backgroundColor = "#C0C0C0";
              buttonKey.style.fontSize = "25px";
              buttonKey.style.marginBottom = "10px";
              buttonKey.style.marginLeft = "5px";
              buttonKey.style.marginRight = "5px";
              document.body.appendChild(buttonKey);
              buttonId++;
  
  
  
              buttonKey.addEventListener("click", function (event) {
                  selectMark(event, event.srcElement);
                  checkIsWinner(event, event.srcElement);
  
              });
          }
  
      });
  
      function selectMark(currentObject, currentType) {
  
          if (chance % 2 != 0) {
              player1 = 'x';
              document.getElementById(currentType.id).innerHTML = player1;
              document.getElementById(currentType.id).style.backgroundColor = '#238EE1';
  
              console.log("player 1 -x")
          }
          else {
              player2 = 'o';
              document.getElementById(currentType.id).innerHTML = player2;
              document.getElementById(currentType.id).style.backgroundColor = '#FF1010';
              console.log("player2 - o")
          }
          chance++;
      }
  
  
      function checkIsWinner(currentObject, currentType) {
  
          winningCombinations = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 4, 7], [2, 5, 8], [3, 6, 9],
          [1, 5, 9], [3, 5, 7]];
  
          var element = document.getElementById(currentType.id);
          var tie = 0;
  
          for (var column = 0; column &lt; 8; column++) {
  
  
              answer1 = winningCombinations[0][column];
              answer2 = winningCombinations[1][column];
              answer3 = winningCombinations[2][column];
  
  
              if (element.innerHTML == 'x' &amp;&amp;
                  (id == answer1 &amp;&amp; id == answer2
                      &amp;&amp; id == answer3)) {
                  console.log("player 1 is the Winner");
                  return false;
              }
              else if (element.innerHTML == 'o' &amp;&amp;
                  (id == answer1 &amp;&amp; id == answer2
                      &amp;&amp; id == answer3)) {
                  console.log("player 2 is the Winner");
                  return false;
              }
              else {
                  tie++;
                  if (tie == 8) {
                      console.log("Its a Tie");
                  }
                  console.log(element.id);
              }
          }
  
  
      }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://code.jquery.com/jquery-3.3.1.js"&gt;&lt;/script&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Tic Tac Toe&lt;/title&gt;
  &lt;style&gt;
  &lt;/style&gt;
  &lt;/head&gt;
  
   &lt;body&gt;
  &lt;div id="displaytable"&gt;&lt;/div&gt;
  
   &lt;/body&gt;
  
   &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I am creating a tictactoe game where i have 9 buttons. I have given an id to every button and added an addEventListener to the button. Now i to want to check the Winner, so i need to retrieve the button id's and find if the combination works.I have tried to retrieve using various notations it didn't work, here in this code i have posted it with buttonKey.id still its non-functional. How to retrieve that. Please help. </p>