-1

I want to be able to create empty tables on my page with a Create table button, but can't figure out how to do it.

I've tried looking some stuff up, but most of the things I see on tables just have you making a table in your html file instead of one being created with a button.

Syed mohamed aladeen
  • 6,507
  • 4
  • 32
  • 59
agaiuqer
  • 21
  • 5

2 Answers2

0

So this is how you create an empty table element. Please note that without any content and/or dimensions your table will not display anything (which is why I added the CSS part).

If that is not what you consider an empty table, please be more specific in your requirements.

document.querySelector('button').addEventListener('click', () => {
  const table = document.createElement('table');
  document.body.appendChild(table);
})
table {
  border: 4px solid red;
  height: 100px;
  width: 200px;
}
<button type="button">Create an empty table</button>
connexo
  • 53,704
  • 14
  • 91
  • 128
-3

You can't do this with pure HTML, because HTML is just a markup language.

Do you know anything about Javascript? You'll probably want to hook an onclick handler to the button. You'll need the handler to create a table and insert it into the correct location in the DOM.

zachdj
  • 354
  • 2
  • 8