Can JavaScript place HTML code into Div...?

Discussion in 'Javascript' started by Tom Szabo, Nov 16, 2004.

  1. Tom Szabo

    Tom Szabo Guest

    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
    Tom Szabo, Nov 16, 2004
    #1
    1. Advertising

  2. Tom Szabo

    Evertjan. Guest

    Tom Szabo wrote on 16 nov 2004 in comp.lang.javascript:
    > 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(){


    document.getElementById("div1").innerHTML="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???





    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress,
    but let us keep the discussions in the newsgroup)
    Evertjan., Nov 16, 2004
    #2
    1. Advertising

  3. Tom Szabo

    Tom Szabo Guest

    Thanks, it does exactly what I needed,

    Thanks again,

    Tom


    "Evertjan." <> wrote in message
    news:Xns95A3ADAA3F1E7eejj99@194.109.133.29...
    > Tom Szabo wrote on 16 nov 2004 in comp.lang.javascript:
    > > 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(){

    >
    > document.getElementById("div1").innerHTML="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???

    >
    >
    >
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress,
    > but let us keep the discussions in the newsgroup)
    >
    Tom Szabo, Nov 16, 2004
    #3
  4. JRS: In article <>, dated Wed, 17 Nov 2004
    02:50:20, seen in news:comp.lang.javascript, Tom Szabo
    <> posted :

    Please place responses after trimmed quotes - see newsgroup FAQ, 2.3.

    >Thanks, it does exactly what I needed,


    In most but not all browsers - see FAQ, 4.15.

    >"Evertjan." <> wrote in message
    >news:Xns95A3ADAA3F1E7eejj99@194.109.133.29...


    >> document.getElementById("div1").innerHTML="Hello"


    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
    Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
    Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
    Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
    Dr John Stockton, Nov 16, 2004
    #4
  5. Tom Szabo

    Evertjan. Guest

    Dr John Stockton wrote on 16 nov 2004 in comp.lang.javascript:
    >>> document.getElementById("div1").innerHTML="Hello"

    >>Thanks, it does exactly what I needed,

    > 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.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress,
    but let us keep the discussions in the newsgroup)
    Evertjan., Nov 17, 2004
    #5
  6. JRS: In article <Xns95A45FEA9DB0Beejj99@194.109.133.29>, dated Wed, 17
    Nov 2004 08:25:39, seen in news:comp.lang.javascript, Evertjan.
    <> posted :
    >Dr John Stockton wrote on 16 nov 2004 in comp.lang.javascript:
    >>>> document.getElementById("div1").innerHTML="Hello"
    >>>Thanks, it does exactly what I needed,

    >> 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.


    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.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr John Stockton, Nov 17, 2004
    #6
  7. Tom Szabo

    Evertjan. Guest

    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.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress,
    but let us keep the discussions in the newsgroup)
    Evertjan., Nov 19, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. K Viltersten

    <div ... /> and <div ...></div>

    K Viltersten, Mar 30, 2009, in forum: ASP .Net
    Replies:
    4
    Views:
    705
  2. CaptCaveman1

    Place div beneath another div

    CaptCaveman1, Feb 6, 2011, in forum: HTML
    Replies:
    2
    Views:
    726
    richard
    Feb 6, 2011
  3. Tom Szabo

    Can JS place html code into a DIV ????

    Tom Szabo, Nov 16, 2004, in forum: Javascript
    Replies:
    4
    Views:
    99
    Julian Turner
    Nov 16, 2004
  4. Sergio del Amo
    Replies:
    4
    Views:
    220
  5. Replies:
    2
    Views:
    93
Loading...

Share This Page