Get value by click on javascript table created on the fly
<p>I want to create a table with javascript on the fly and able to get all the value in the row by select that row. Currently I add a click event but it doesnt seem to work how it suppose to be.</p>

<p>Code:</p>

<pre><code>var table = document.getElementById("here_table");
table.innerHTML = "";
for (var i = 0; i &lt; 5; i++) {
  var js = "apple";
  var tr = document.createElement("tr");
  var td = document.createElement("td");
  tr.addEventListener('click', myFunction(i));
  td.innerHTML = js + i;
  tr.appendChild(td);
  td = document.createElement("td");
  td.innerHTML = js + 1 + i;
  tr.appendChild(td);
  table.appendChild(tr);
}

function myFunction(x) {
  var cells = document.getElementsByTagName("tr");
  alert("Value of row " + cells);
}
</code></pre>

<p><a href="https://jsfiddle.net/6vjuwonz/" rel="nofollow">https://jsfiddle.net/6vjuwonz/</a></p>