Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Matt McDonald Newsgroups: comp.lang.javascript Subject: Re: FAQ Topic - How do I modify the content of the current page? (2012-05-23) Date: Tue, 22 May 2012 18:07:24 -0600 Organization: A noiseless patient Spider Lines: 29 Message-ID: References: <4fbc1a7a$0$294$14726298@news.sunsite.dk> Reply-To: matt@fortybelow.ca Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 23 May 2012 00:07:25 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="o3RIB98y67SlfDKoxPQiYw"; logging-data="9195"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/aBT8/1zZCCGMkY8Gbde4JwOYCdpIYRfg=" User-Agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 In-Reply-To: <4fbc1a7a$0$294$14726298@news.sunsite.dk> Cancel-Lock: sha1:kqSHceMzDLbMn0UO7c7/yHf4zig= Xref: csiph.com comp.lang.javascript:14105 On 12-05-22 05:00 PM, FAQ server wrote: > 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. A more general approach is simply to use the `nodeValue` property, though both are acceptable. > 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. The DOM 4 specification states[0] that textual content replacement (`Node::textContent`, setting) is to be done by clearing the `childNodes` of a node and appending a text node containing the new text for Element and DocumentFragment nodes, while simply replacing the `data` (and by proxy the `nodeValue`) for Text, ProcessingInstruction and Comment nodes. I've written a fork of `textContent` (to be released soon) that does precisely this. Since Element nodes are the most desired context, the former behavior is advised. [0]: http://dvcs.w3.org/hg/domcore/raw-file/tip /Overview.html#dom-node-textcontent -- Matt McDonald: Web/Flash Developer; Edmonton, Alberta, Canada