InnerHTML with “=” REPLACES the content… as such the code you had would only have contained the very last line – </tr></td></table> – by the time the script is done running… because first you replace it’s content with the first line, replace it again erasing that first line with the second one, then erase and replace again with the third one.
The switch to += in oddz example means only the first one replaces the content, the latter two add to the end of it.
Though ‘officially’ you’re not supposed to use innerHTML and instead be building with the DOM… Oh, and I hope that snippet isn’t actual code, since if it only has one TD why use a table?
Good catch Ulricht, the </tr> and </td> were indeed reversed.
Also, it’s usually a bad idea to call getElementById over and over as that’s one of the slower functions… when possible, make it one statement; OR put the result in a var and manipulate the result.
$target=document.getElementById(‘addedText’);
$target.innerHTML = ‘<table><tr><td>My text goes here</td></tr></table>’;
Is even faster to execute… and do yourself a favor, stick with single quotes. Double quotes take longer to parse in .js – it’s also easier since you are less likely to be outputting singles, while HTML tags use doubles all the time.