Amra Amra - 6 months ago 48
HTML Question

How to insert text in a td with id, using javascript

I know it may be a simple thing, but I cant figure out,I am trying to insert some text coming from a javascript function onload event into a td.

<html>
<head>
<script type="text/javascript">
function insertText ()
{
//function to insert any text on the td with id "td1"
}
</script>
</head>
<body onload="javascript:insertText()">
<table>
<tr>
<td id="td1">
</td>
</tr>
</table>
</body>
</html>


Any help?

Thanks.

Answer
<html>

<head>
<script type="text/javascript">
function insertText () {
    document.getElementById('td1').innerHTML = "Some text to enter";
}
</script>
</head>

<body onload="insertText();">
    <table>
        <tr>
            <td id="td1"></td>
        </tr>
    </table>
</body>
</html>