469,626 Members | 1,460 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

about document.image1

Hi, all

I found I can get the img element named with "image1" in a html by
using "document.image1" with javascript. It's very convenient because
I don't need to use the long method like getElementByName etc. I
wonder if this approach is the part of the DOM? I have checked the DOM
specification, but found nothing. Can somebody give me clue? Thanks.

Regards.
Nov 7 '08 #1
3 1185
ha******@gmail.com wrote on 07 nov 2008 in comp.lang.javascript:
I found I can get the img element named with "image1" in a html by
using "document.image1" with javascript. It's very convenient because
I don't need to use the long method like getElementByName etc. I
wonder if this approach is the part of the DOM? I have checked the DOM
specification, but found nothing. Can somebody give me clue? Thanks.
This is one of the crazy "features" of IE,
not cross-browser safe,
and ever a source of errors in IE itself.

Do not use it on open webpages.

Names are not unique in HTML, IDs are.
It is quite legal to give multiple images the same name.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Nov 7 '08 #2
ha******@gmail.com wrote:
I found I can get the img element named with "image1" in a html by
using "document.image1" with javascript. It's very convenient because
I don't need to use the long method like getElementByName etc. I
wonder if this approach is the part of the DOM?
It must be part of a DOM, otherwise it would not work. You should be asking
instead whether it is sanctioned by a Web standard. No, it is not. But see
below.
I have checked the DOM specification, but found nothing. Can somebody
give me clue? Thanks.
Read the ECMAScript Language Binding section of the W3C DOM Level 2 HTML
Specification on "objects that implement the HTMLDocument interface" and on
"objects that implement the HTMLCollection interface" to see that

document.images["image1"]

would be standards-compliant. It is also backwards-compatible because the
earliest implementations, that of NN 3.0 and IE 3.0 (the so-called "DOM
Level 0"), already supported it.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Nov 7 '08 #3
SAM
Le 11/7/08 7:44 AM, ha******@gmail.com a écrit :
Hi, all

I found I can get the img element named with "image1" in a html by
using "document.image1" with javascript.
It's the old way to get elements, and here : image

But the element must have a 'name' and not only an 'id'.
Take care if you have only ids that only IE will run with this feature.

<img name="image1" id="image1" src blah >

When a browser reads an html file its javascript engine parses the code,
building all the JS trees (the old ones and the DOM).

JS trees :
- document.images
- document.forms (and for each form : document.forms[i].elements)
- document.anchors
- document.links
- ...
It's very convenient because
I don't need to use the long method like getElementByName etc.
usually you have to do :

document.images['image1']
this approach is the part of the DOM?
Absolutely not ! the DOM is the DOM.
You get or set elements via the Document Model Objects

I think javascript DOM functions have been added with version 1.5

I have checked the DOM specification, but found nothing.
Of course :
most of the time it is forbidden to give a 'name' to the elements,
so the DOM doesn't know 'name', or almost not
document.getElementsByName('aName');
will return the collection of elements named 'aName'.
Can somebody give me clue? Thanks.
search about JavaScript 1.2

--
sm
Nov 7 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by michaaal | last post: by
5 posts views Thread by Nospam | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.