Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

innerHTML Not Displaying

Status
Not open for further replies.

hiyatran

Technical User
Aug 7, 2010
21
CA
I can't seem to get my innerHTML to display my content.

This works fine, if I was to put it all in one line.
Code:
document.getElementById('addedText').innerHTML =  '<table><tr><td>'+"My text goes here"+'</tr></td></table>';

If I was to break it up, which I wanted then nothing seem to show up.
Code:
   document.getElementById('addedText').innerHTML = '<table><tr><td>';
   document.getElementById('addedText').innerHTML = "My text goes here";
   document.getElementById('addedText').innerHTML = '</tr></td></table>';


Here's my code
Code:
<html>
<head>
<script type="text/javascript"> 
function display() {
   document.getElementById('addedText').innerHTML = '<table border=1><tr><td>';
   document.getElementById('addedText').innerHTML = "My text goes here";
   document.getElementById('addedText').innerHTML = '</tr></td></table>';
}
</script>
</head>

<body onload="display()">
<div id="addedText"></div>
</body>
</html>

thanks

 
Try:
Code:
document.getElementById('addedText').innerHTML [COLOR=red][b]+[/b][/color]= "My text goes here";   document.getElementById('addedText').innerHTML [COLOR=red][b]+[/b][/color]= '</tr></td></table>';

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
As pointed out by Lyndon, you are overwriting the innerHTML each time you set it, so the best you are going to get is the last set of "</td></tr></table>" which doesn't really do anything.

If you want to add more text to the property then concatenate, in fact it would be better to do everything in a single call of the getElementById instead of multiple calls.

Code:
document.getElementById('addedText').innerHTML = '<table border=1><tr><td>' + 'My text goes here' + '</tr></td></table>';

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top