Nick
Nick

Reputation: 597

Creating simple table in javascript

I'm just trying to create simple javascript function that outputs a small table but can't seem to get it working.

<html>
<head>
    <meta charset ="utf-8">
    <title>Test Table</title>
    <script type = text/javascript>

        function drawTable()
        {
            var tableDiv = document.getElementById( "numbersTable" );

            tableDiv.innerHTML = "<table>" + 
            "<caption>Numbers Table</caption>" +
            "<thead><th>Number</th><th>Square</th><th>Cube</th></thead>" +
            "<tbody><tr><td>1</td><td>2</td><td>3</td></tr>" +
            "</tbody></table>";
        }

    </script>
</head>
<body>
<div id = "numbersTable"></div>
</body>

Can anyone see where the problem is?

Upvotes: 1

Views: 2226

Answers (1)

pwolaq
pwolaq

Reputation: 6381

  1. you don't call drawTable()
  2. remember to call it after <div id="numbersTable"></div>

Upvotes: 3

Related Questions