Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

innerHtml isn't inserting the text I need in my table header

I am trying to add text to a header using JavaScript. I can add the elements for a table header, table row, and table data using the following code. But I can’t seem to get innerHtml to work for inserting text into the table data element. I am not much of a JavaScript kind of guy, but the service I am using only supports raw html + javascript in it’s webservers.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Stack Overflow Don't Judge Me!</title>
</head>
<body>
    <table id="table1">

    </table>
    <script>
        function writeHeaderToTable() {
            var tsTable = document.querySelector("#table1");    //Find the table with id of ts
            var tsHeader = tsTable.createTHead();               // Create a header for that table.
            var tsHeaderRow = tsHeader.insertRow(0);            // insert a row in that header.
            var tsCell = tsHeaderRow.insertCell(0);             // insert a cell in that row.
            tsCell.innerHtml = "<b>This is a header</b>";       // write to that cell some text. <--- This is not working! (╯°□°)╯︵ ┻━┻
        }
        writeHeaderToTable();
    </script>
</body>
</html>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You need to use innerHTML not innerHtml

element.innerHTML is the correct syntax.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading