title: Getting an attribute from a forLoop element using onclick function
body: <p>I wanted to get the value of a forLoop element by using getAttribute with an 'onclick' attribute as well. But what I'm getting is the end value already. How do you get the value per loop on the exact value element being clicked? Here is my code;</p>
  
  <pre><code>const btn = document.createElement('button');
  const scrOutput = document.createElement('p');
  const numbers = ['0','1','2','3','4','5','6','7','8','9'];
  
  // For Loop Condition
  for (let i=0; i&lt;numbers.length; i++) {
    btn.setAttribute('onclick', 'showOutput()');
    btn.setAttribute('value', numbers[i]);
    btn.innerText = numbers[i];
    document.getElementById('numbers').innerHTML += btn.outerHTML;
    const x = btn.getAttribute('value', numbers[i]);
    console.log(x);  
  }
  
  function showOutput(){
    const btnVal = btn.getAttribute('value');
    scrOutput.innerText = btnVal;
    document.getElementById('screen').innerHTML = scrOutput.outerHTML;
    console.log(btnVal);
  }
  </code></pre>