Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <8973725.hmDRQCkskN@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sun, 03 Feb 2013 02:03:49 +0100 User-Agent: KNode/4.8.5 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. text replacement ?? Newsgroups: comp.lang.javascript References: MIME-Version: 1.0 Lines: 63 NNTP-Posting-Date: 03 Feb 2013 02:03:50 CET NNTP-Posting-Host: 97e5cb81.newsspool4.arcor-online.net X-Trace: DXC=ZX[9HCI7UTWV;Ef1`Jk54\4IUK On 3/02/2013 8:10 AM, Jukka K. Korpela wrote: >> 2013-02-02 22:41, Mel Smith wrote: >>> I wish to change the textual content of the following >>> element. >>> >>> This is original error msg >>> >>> I have tried document.getElementById("ierrmsg").value ="new error >>> msg" ; >>> >>> .. and I've also tried to do .nodeValue, .text, etc. >> >> Normal elements don’t have such properties. Nonsense. >> The practical choice is the innerHTML property: >> document.getElementById("ierrmsg").innerHTML = "new msg" ; > > or > > document.getElementById("ierrmsg").firstChild.nodeValue = "new msg"; > > should also work. Of course the element would have to exist before you > can apply any change to it. Neither the “innerHTML” property nor the “nodeValue” property of the first text child node are usually equivalent to the *text* content of the corresponding element. Per W3C DOM Level 3 Core, all elements have a “textContent” property that can be read from and assigned to. document.getElementById("ierrmsg").textContent = "new msg"; It is supported by many DOM implementations, but not MSHTML < 9. For the latter, you need to remove all child nodes and create a new text child node: if (typeof el.textContent != "undefined") { el.textContent = text; } else { while (el.lastChild) el.removeChild(el.lastChild); el.appendChild(document.createTextNode(text)); } See also jsx.dom.setTextContent(). An assignment to the “innerHTML” property is not equivalent to that because there the value right-hand side will be parsed, and the property is not available in XML mode. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.