Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #19325
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Accessing image property in IE when there's a period in the html ID? |
| Date | 2013-04-18 10:07 +0200 |
| Organization | albasani.net |
| Message-ID | <kko9ke$6tt$1@news.albasani.net> (permalink) |
| References | <kkn90j$nuv$1@news.albasani.net> <kknb7u$rnl$1@news.albasani.net> <kknu2c$imm$1@dont-email.me> |
On 2013-04-18 06:53, Jukka K. Korpela wrote: > 2013-04-18 2:29, Stefan Weiss wrote: >> On 2013-04-18 00:50, Tuxedo wrote: >>> If an image element has an html ID containing a period, such as for example: >>> <img src="some.jpg" id="0010.0"> >> >> Just as an aside: if you use periods in id attribute values, you need to >> use HTML5, because this is invalid in earlier HTML versions. > > The id attribute value is indeed invalid in HTML 4, but not for that > reason. The period is allowed in id attribute values, but such a value > must not begin with a digit, by HTML 4 rules: > http://www.w3.org/TR/REC-html40/types.html#type-id Right, thanks. > On the other hand, this is just a formality. Browsers do what browsers > do, actually accepting id="0010.0", and there is no "using HTML5" that > would be needed for this. In validation, it matters which HTML version > you validate against, but that's a different issue. Sure, we don't have to write valid documents, and browsers will try to make sense of whatever we throw at them. But I see validation as more than a mere formality - it's a part of debugging: when something doesn't work as expected, validation allows me to give up, blame the browser and file a bug report. >> The problem is not the period, but that "0010.0" gets converted to the >> numeric value 10 when you try to use it as an index for document.images. > > This is what actually happens in IE, as you can see by testing with a > page that contains 11 or more <img> elements. But this is a bug in IE, > isn't it? I can't see any justification for such a conversion in a > property accessor. After all, document.images is not an array but an > array-like object, and in this case it has a property named "0010.0". It's not a bug if it's documented ;) Unfortunately, Microsoft's DOM documentation is so grotesquely bad that I can't even find document.images, and their page on HTMLCollection is not very helpful. The DOM HTMLCollection interface only specifies a length property and item() and namedItem() accessor methods. item() is called with a numeric index, and namedItem() with a string (id or name). What happens when the collection is accessed like an array is up to the implementation. (This can't be in the specification, because it's not even possible in most languages.) For the same reason, it's unspecified if IDs or names should show up as properties of document.images. They do in IE8 (names are preferred over IDs), Firefox (with both names and IDs), but not at all in Chrome. So, my guess is that when a collection like document.images is accessed like an array, the getter looks at the argument and decides which accessor method to use. If the argument looks numeric, it uses item(), otherwise it uses namedItem(). This is where IE apparently decides that "0010.0" is numeric enough to use item(). - stefan
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Accessing image property in IE when there's a period in the html ID? Tuxedo <tuxedo@mailinator.com> - 2013-04-18 00:50 +0200
Re: Accessing image property in IE when there's a period in the html ID? Stefan Weiss <krewecherl@gmail.com> - 2013-04-18 01:29 +0200
Re: Accessing image property in IE when there's a period in the html ID? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-04-18 07:53 +0300
Re: Accessing image property in IE when there's a period in the html ID? Stefan Weiss <krewecherl@gmail.com> - 2013-04-18 10:07 +0200
Re: Accessing image property in IE when there's a period in the html ID? Tuxedo <tuxedo@mailinator.com> - 2013-04-18 08:39 +0200
Re: Accessing image property in IE when there's a period in the html ID? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-18 11:06 +0200
Re: Accessing image property in IE when there's a period in the html ID? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-04-18 13:05 +0300
Re: Accessing image property in IE when there's a period in the html ID? Andrew Poulos <ap_prog@hotmail.com> - 2013-04-18 20:21 +1000
Re: Accessing image property in IE when there's a period in the html ID? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-18 12:39 +0200
Re: Accessing image property in IE when there's a period in the html ID? Stefan Weiss <krewecherl@gmail.com> - 2013-04-18 16:38 +0200
Re: Accessing image property in IE when there's a period in the html ID? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-19 01:25 +0200
Re: Accessing image property in IE when there's a period in the html ID? Stefan Weiss <krewecherl@gmail.com> - 2013-04-19 19:40 +0200
Re: Accessing image property in IE when there's a period in the html ID? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-19 19:52 +0200
Re: Accessing image property in IE when there's a period in the html ID? "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2013-04-18 13:56 +0300
Re: Accessing image property in IE when there's a period in the html ID? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-18 13:19 +0200
csiph-web