F
FAQ server
-----------------------------------------------------------------------
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.
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(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx
http://developer.mozilla.org/en/Whitespace_in_the_DOM
http://developer.mozilla.org/en/docs/DOM:element.innerHTML
http://jibbering.com/faq/faq_notes/alt_dynwrite.html
The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/
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.
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(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx
http://developer.mozilla.org/en/Whitespace_in_the_DOM
http://developer.mozilla.org/en/docs/DOM:element.innerHTML
http://jibbering.com/faq/faq_notes/alt_dynwrite.html
The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/