I know it may be a simple thing, but I can't 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?
An id on a <td> tag assigns an identifier to the table cell. The identifier must be unique across the page.
The <caption> tag must be inserted immediately after the <table> tag. Tip: By default, a table caption will be center-aligned above a table. However, the CSS properties text-align and caption-side can be used to align and place the caption.
Use the insertAdjacentText() method to append text to a paragraph element, e.g. p. insertAdjacentText('beforeend', 'my text') . The method inserts a new text node at the provided position, relative to the element it was called on.
td elements don't have value. What you are looking for is to get the value of the attribute value of that element.
<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>
append a text node as follows
var td1 = document.getElementById('td1'); var text = document.createTextNode("some text"); td1.appendChild(text);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With