Can JavaScript place HTML code into Div...?

T

Tom Szabo

Hi,

What I like to know is if it is possible to have a JavaScript writing code
into a DIV section, that is say during load or on a certain event in the
same page it would insert the word "hello"

----------------
.......
<script>
function insert_hello(){
?????
}
</script>

<body onload="insert_hello()"....


<div id=div1 name=div1>
</div>
....

-----------------

...so it would display the word "hello" in the area taken up by the <DIV
id=div1 name=div1>
I understand you can change attributes/properties like the value of a text
field but what about this scenario???


TIA,

Tom
 
E

Evertjan.

Dr John Stockton wrote on 16 nov 2004 in comp.lang.javascript:
In most but not all browsers - see FAQ, 4.15.

While this is true, John,
the OP clearly shows a to be a newbee,
and a complete solution would scare the OP off,
which is worse IMHO, than the incompliance.

btw: Having javascript switched off could be
a far more probable problem,
than having a innerHTML incompliant browser.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Wed, 17
Nov 2004 08:25:39, seen in Evertjan.
Dr John Stockton wrote on 16 nov 2004 in comp.lang.javascript:

While this is true, John,
the OP clearly shows a to be a newbee,
and a complete solution would scare the OP off,
which is worse IMHO, than the incompliance.

btw: Having javascript switched off could be
a far more probable problem,
than having a innerHTML incompliant browser.

It is not for us to decide what the reader is allowed to know; it is for
the reader to decide what he needs to support, knowing that the solution
you gave is not universal. A reference to the FAQ achieves that
warning.

So does "Older browsers may not know getElementById; it can be provided
if needed by
if (document.all && !document.getElementById) {
document.getElementById = function(id) {
return document.all[id] } } // "

// (which seems OK to me, and works in IE4.)

Moreover, since he *is* asking about something which the FAQ answers,
then he should in any case be referred to the FAQ; he may very well find
there answers to future questions.
 
E

Evertjan.

Dr John Stockton wrote on 17 nov 2004 in comp.lang.javascript:
Moreover, since he *is* asking about something which the FAQ answers,
then he should in any case be referred to the FAQ;

"should"?

I don't think so, John.

A straight answer is not against netiquette, even if there is a NG-FAQ.

I would agree on "could".
he may very well find there answers to future questions.

Undoubtedly, he may.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top