When i click on a h1 a table should appear but does not work?

This is part of a JavaScript college work, When i click on the h1 I want a table to display but Iam having trouble displaying the tr.
The table is only displaying the td and not the tr.

<!DOCTYPE html>
table, td {
  border: 1px solid black;

<h1 onclick="myFunction()">Table</h1>

function myFunction() {
  var x = document.createElement("TABLE");
  x.setAttribute("id", "myTable");

  var y = document.createElement("TR");
  y.setAttribute("id", "myTr");

  var z = document.createElement("TD");
  var t = document.createTextNode("cell");


Code works as expected for me.

a TR has no ‘display’ per-se, it’s a container element that holds TD’s.

Oh thanks was so confused.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.