From: FAQ server on
-----------------------------------------------------------------------
FAQ Topic - How do I modify the content of the current
page?
-----------------------------------------------------------------------

Using the non-standard but widely implemented
` innerHTML ` property:
` <div id="anID">Some Content</div> ` with script:

document.getElementById("anID").innerHTML =
"Some <em>new</em> Content";

Where ` "anID" ` is the (unique on the HTML page)
` id ` attribute value of the element to modify.

All versions of Internet Explorer exhibit problems with innerHTML, including:

*
* Fails with FRAMESET, HEAD, HTML, STYLE, SELECT,
OBJECT, and all TABLE-related elements.

* Replaces consecutive whitespace characters with a single space.
* Changes attribute values and order of appearance.
* Removes quotations around attribute values.

If the new content is only text and does not need to replace existing HTML,
it is more efficient to modify the ` data ` property of a text node.

document.getElementById("anID").firstChild.data = "Some new Text";

Compatibility Note: Implementations have been known to split long text
content among several adjacent text nodes, so replacing the data of the
first text node may not replace all the element's text. The ` normalize `
method, where supported, will combine adjacent text nodes.

Note: Make sure the element exists in the document (has been parsed) before trying to
reference it.

http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-FF21A306

http://msdn.microsoft.com/en-us/library/cc304097%28VS.85%29.aspx

http://msdn.microsoft.com/en-us/library/ms533897%28VS.85%29.aspx

http://developer.mozilla.org/en/Whitespace_in_the_DOM

http://developer.mozilla.org/en/docs/DOM:element.innerHTML

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#html-fragment-serialization-algorithm

(draft)


The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/

--

The sendings of these daily posts are proficiently hosted
by http://www.pair.com.

From: Dr J R Stockton on
In comp.lang.javascript message <4c1562fb$0$276$14726298(a)news.sunsite.dk
>, Sun, 13 Jun 2010 23:00:03, FAQ server <javascript(a)dotinternet.be>
posted:

>FAQ Topic - How do I modify the content of the current
>page?

You have ignored previous discussion, in which it was pointed out that
answering the Subject question involves describing two stages :

First, obtain a reference to an appropriate part of the document.
Secondly, apply the change.

There are various ways, apart from getElementById, of getting such a
reference.

There are various ways, apart from writing or rewriting text or HTML, of
changing the visible content (and it is the content as seen that was
being asked about). For example, styling display to none or block is
likely to be better for revealing/concealing sections of fixed material.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
From: Dr J R Stockton on
In comp.lang.javascript message <hv90gu$j2k$1(a)news.eternal-
september.org>, Tue, 15 Jun 2010 15:57:39, Garrett Smith
<dhtmlkitchen(a)gmail.com> posted:

>On 6/15/2010 2:34 PM, Dr J R Stockton wrote:
>> In comp.lang.javascript message<4c1562fb$0$276$14726298(a)news.sunsite.dk
>>> , Sun, 13 Jun 2010 23:00:03, FAQ server<javascript(a)dotinternet.be>
>> posted:
>>
>>> FAQ Topic - How do I modify the content of the current
>>> page?
>>
>> You have ignored previous discussion, in which it was pointed out that
>> answering the Subject question involves describing two stages :
>>
>> First, obtain a reference to an appropriate part of the document.
>> Secondly, apply the change.
>>
>
>The question itself is too vague. Perhaps it should be:
>
>"How to I modify the content of an Element"?

Wrong : the Subject is the sort of question that gets asked. Indeed, I
may be its original asker. If so, the original answer was specific to
the circumstances which I indicated; the present FAQ answer should be
more general.

The answer could be like
See Section ### "Creating and Inserting a new page element", or
Section ### "Moving an element of a page", or
Section ### "Getting a reference to an element of a page" and
Section ### "Altering a given element of a page"
if those modules can be used to answer other questions.


>> There are various ways, apart from getElementById, of getting such a
>> reference.
>>
>> There are various ways, apart from writing or rewriting text or HTML, of
>> changing the visible content (and it is the content as seen that was
>> being asked about). For example, styling display to none or block is
>> likely to be better for revealing/concealing sections of fixed material.
>>
>
>Styling is not content.

You are a mere nerd, and are manifestly unfitted to be a FAQ maintainer.

To a normal person, that question refers primarily to the visual
appearance of the page.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (RFCs 5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFCs 5536/7)
From: Jeff North on
On Thu, 17 Jun 2010 17:13:22 +0100, in comp.lang.javascript Dr J R
Stockton <reply1024(a)merlyn.demon.co.uk>
<TsRF9eKimkGMFw6M(a)invalid.uk.co.demon.merlyn.invalid> wrote:

>| In comp.lang.javascript message <hv90gu$j2k$1(a)news.eternal-
>| september.org>, Tue, 15 Jun 2010 15:57:39, Garrett Smith
>| <dhtmlkitchen(a)gmail.com> posted:
>|
>| >On 6/15/2010 2:34 PM, Dr J R Stockton wrote:
>| >> In comp.lang.javascript message<4c1562fb$0$276$14726298(a)news.sunsite.dk
>| >>> , Sun, 13 Jun 2010 23:00:03, FAQ server<javascript(a)dotinternet.be>
>| >> posted:
>| >>
>| >>> FAQ Topic - How do I modify the content of the current
>| >>> page?
>| >>
>| >> You have ignored previous discussion, in which it was pointed out that
>| >> answering the Subject question involves describing two stages :
>| >>
>| >> First, obtain a reference to an appropriate part of the document.
>| >> Secondly, apply the change.
>| >>
>| >
>| >The question itself is too vague. Perhaps it should be:
>| >
>| >"How to I modify the content of an Element"?
>|
>| Wrong : the Subject is the sort of question that gets asked. Indeed, I
>| may be its original asker. If so, the original answer was specific to
>| the circumstances which I indicated; the present FAQ answer should be
>| more general.
>|
>| The answer could be like
>| See Section ### "Creating and Inserting a new page element", or
>| Section ### "Moving an element of a page", or
>| Section ### "Getting a reference to an element of a page" and
>| Section ### "Altering a given element of a page"
>| if those modules can be used to answer other questions.
>|
>|
>| >> There are various ways, apart from getElementById, of getting such a
>| >> reference.
>| >>
>| >> There are various ways, apart from writing or rewriting text or HTML, of
>| >> changing the visible content (and it is the content as seen that was
>| >> being asked about). For example, styling display to none or block is
>| >> likely to be better for revealing/concealing sections of fixed material.
>| >>
>| >
>| >Styling is not content.
>|
>| You are a mere nerd, and are manifestly unfitted to be a FAQ maintainer.
>|
>| To a normal person, that question refers primarily to the visual
>| appearance of the page.

Maybe the title should be:
How do I change the text of the current page.
From: Jeff North on
On Thu, 17 Jun 2010 19:23:58 -0700, in comp.lang.javascript Garrett
Smith <dhtmlkitchen(a)gmail.com>
<hvelbp$d8f$1(a)news.eternal-september.org> wrote:

>| On 6/17/2010 7:08 PM, Jeff North wrote:
>| > On Thu, 17 Jun 2010 17:13:22 +0100, in comp.lang.javascript Dr J R
>| > Stockton<reply1024(a)merlyn.demon.co.uk>
>| > <TsRF9eKimkGMFw6M(a)invalid.uk.co.demon.merlyn.invalid> wrote:
>| >
>|
>| [snip overquote]
>|
>| > Maybe the title should be:
>| > How do I change the text of the current page.
>|
>| Content includes more than text; it includes elements.
>|
>| The general sense I was going for is explained here:
>|
>| http://en.wikipedia.org/wiki/Web_content
>|
>| | Web content is the textual, visual or aural content that is
>| | encountered as part of the user experience on websites. It may
>| | include, among other things: text, images, sounds, videos and
>| | animations.
>|
>| The term content is also used here:
>| http://www.w3.org/TR/WCAG10/#content-structure
>| http://www.w3.org/TR/WCAG20/#glossary
>|
>| Garrett

People seem to be getting their knickers in a knot over the words
'content' and 'modify'.

Maybe at the top of this FAQ entry you should include the wikipedia
quote just so it is clear to everyone what content means :-)