title: How to check a table is empty or not using javascript
body: <p>So i have a script like this to make a 2x2 table by javascript</p>
  
  <pre><code>function createtable(){
            var tbl = document.getElementById('x');
              if (tbl.contains()==false){
                tbl.setAttribute('border', '1');
                var tbdy = document.createElement('tbody');
                for (var i = 0; i &lt; 2; i++) {
                  var tr = document.createElement('tr');
                  for (var j = 0; j &lt; 2; j++) {         
                      var td = document.createElement('td');
                      tr.appendChild(td);
                      td.style.height='50px';
                      td.style.width='50px';
                  }
                  tbdy.appendChild(tr);
                }
                tbl.appendChild(tbdy);
          }
  
  &lt;form&gt;
      &lt;input type="button" value="Create Table" onclick="createtable()"&gt; &lt;br&gt;
  &lt;/form&gt;
  &lt;table id="x"&gt; &lt;/table&gt;
  </code></pre>
  
  <p>I want to check if table x contains anything or not to create itself. Im trying to use the contains() to check but it doesnt work.</p>