.innerHTML is used when you trigger an event but if you just want to display the text how would you go about do it??
I don't want to used document.writeln because it will "Wipe out all the contents" of that page.
So I have some HTML text and javascript text. I would like both to display on my page.

Here's my code

<html>
<head>

<script type="text/javascript"> 
function display() {
   document.writeln("How do I make both text appear");
}
</script>
</head>

<body onload="display()">
I would like this text in the body to remain.

<script type="text/javascript">
   display();
</script>


</body>
</html>

thanks

Hiyatran,

The body onload event occurs after a document has finished loading. Attempting to write content after this has happened will invalidate the structure of your HTML document. This might explain why you're seeing a blank page.

To add additional content to a page you'll need to obtain a reference to an existing element and then modify it in some way. One way to achieve this is to do something like...

<html>
<head>
<title></title>
<script type="text/javascript">
function foobar() {
    document.getElementById('placeholder').innerHTML = "The Martians are coming!";
}
</script>
</head>
<body onload="foobar()">
<p>Hello Earthling.</p>
<p id="placeholder"></p>
</body>
</html>

The code above works by obtaining a reference to an existing 'p' element, identified here as 'placeholder', and then changing the value of its innerHTML property.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.