Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1586396.c5DW0iILPE@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sat, 18 Jan 2014 12:06:13 +0100 User-Agent: KNode/4.11.3 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+&. <55605684.RQav8vfDIM@PointedEars.de> <52d99eb8$0$6552$9b4e6d93@newsspool4.arcor-online.net> <1566847.28b1k6Xl7B@PointedEars.de> <52d9d28c$0$6552$9b4e6d93@newsspool4.arcor-online.net> MIME-Version: 1.0 Lines: 93 NNTP-Posting-Date: 18 Jan 2014 12:06:35 CET NNTP-Posting-Host: 79c8ca29.newsspool4.arcor-online.net X-Trace: DXC=2d[gH7G`:3em7>ihJR;B_c4IUK Thomas 'PointedEars' Lahn wrote: >> Christoph Michael Becker wrote: >>> Thomas 'PointedEars' Lahn wrote: >>>> 5. Avoid the “outerHTML” property. >>> >>> Is there any particular reason besides outerHTML being non standardized >>> (yet)? >> >> Yes. > > What is this reason? The same reason why using “innerHTML” should be avoided: In many cases it is unnecessary and less efficient to work with a serialization of the document (sub)tree instead of with the document (sub)tree itself. In this case, /* * You can pass the property values as arguments instead, * but I will probably never remember the order correctly */ var option = new Option(); option.text = "foo"; option.value = "bar"; var options = select.options; options[options.length] = option; would have been appropriate [HTMLSelectElement::add() and HTMLOptionsCollection::add() are not backwards-compatible]. Whereas, assuming the target “select” element had an ID or name of "baz", the reference value of “select” could have been retrieved via one of - el.form.elements["baz"]; - document.evaluate( '../*[translate(local-name(), "SELCT", "selct") = "select"' + ' and (@id = "baz" or @name = "baz")]', el, null, …); - document.getElementById("baz"); - el.parentNode.getElementsByTagName("select")[index]; - document.getElementsByName("baz")[index]. Preferably in that order. >>> Do the restrictions mentioned in the FAQ section "How do I >>> modify the content of the current page?"[1] apply to outerHTML as well? >> >> Probably. >> >>> And do they still hold for recent IE versions wrt. innerHTML? >> >> I do not know. Which IE versions exactly do you consider “recent”? > > At least IE 11, but even IE 9 (or even earlier?) might have brought > improvements. (I'm quite deliberately omitting any specific JScript > version numbers here.) > > FWIW, I quickly hacked together a simple test and put it on > . It seems that IE 8 still has > the mentioned issues regarding what is tested: > > * Replaces consecutive whitespace characters with a single space. > * Changes (attribute values and) order of appearance. > * Removes quotations around attribute values. ACK. Also, the FAQ entry is incomplete because it does not discuss in more detail the detrimental effects of assigning a value to the “innerHTML” property of certain element objects. > However, IE 11 passes these tests, and according to the emulation mode > even IE 9 does so. Quite interestingly, Firefox 26.0 changes the order > of appearance of the table element's attributes (while Chrome 32.0 and > Opera 12.16 do not). Yet another reason why working with serializations is error-prone. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.