Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #22665
| 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> (permalink) |
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| 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+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg== |
| Subject | Re: Reading outerHTML |
| Newsgroups | comp.lang.javascript |
| References | <4ZydnTNcnrnRy0XPnZ2dnUVZ_h6dnZ2d@westnet.com.au> <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<Cl32<a4Fo<]lROoRa8kF<OcfhCOkj]Fh:bfXX[mDZm8W4\YJNlYUVHKH;GI^gjehMn`ohZViRK\5JG8jkbf |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | csiph.com comp.lang.javascript:22665 |
Show key headers only | View raw
Christoph Michael Becker wrote:
> 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].
<http://www.w3.org/TR/2013/CR-html5-20130806/forms.html#the-select-element>
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.
<http://www.w3.org/TR/2013/CR-html5-20130806/forms.html#dom-fae-form>
<http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226/xpath.html#XPathEvaluator-evaluate>
<http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid>
<http://dom.spec.whatwg.org/#dom-element-getelementsbytagname>
<http://www.w3.org/TR/2013/CR-html5-20130806/dom.html#dom-document-getelementsbyname>
>>> 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
> <http://cmb.bplaced.net/innerhtml1.html>. 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.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
Reading outerHTML Andrew Poulos <ap_prog@hotmail.com> - 2014-01-17 08:58 +1100
Re: Reading outerHTML "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-01-17 08:55 +0200
Re: Reading outerHTML "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-17 11:20 +0100
Re: Reading outerHTML Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-01-17 12:58 +0000
Re: Reading outerHTML "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-17 15:44 +0100
Re: Reading outerHTML Christoph Michael Becker <cmbecker69@arcor.de> - 2014-01-17 22:26 +0100
Re: Reading outerHTML Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-17 16:27 +0100
Re: Reading outerHTML Christoph Michael Becker <cmbecker69@arcor.de> - 2014-01-17 22:21 +0100
Re: Reading outerHTML Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-17 23:32 +0100
Re: Reading outerHTML Christoph Michael Becker <cmbecker69@arcor.de> - 2014-01-18 02:02 +0100
Re: Reading outerHTML "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-18 11:55 +0100
Re: Reading outerHTML Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-18 12:06 +0100
csiph-web