about document.image1

H

hantechs

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.
 
E

Evertjan.

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.
 
T

Thomas 'PointedEars' Lahn

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
 
S

SAM

Le 11/7/08 7:44 AM, (e-mail address removed) 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.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,137
Messages
2,570,794
Members
47,342
Latest member
eixataze

Latest Threads

Top