About the DOM document object

D

Draenox

In an if statement with "document.images" as it's expression, does it
simply check if there are any image elements in an HTML page? I'm
assuming if it finds any that the expression will return true and
execute the statements within the if.

if(document.images)
{
// various statements....
}
 
E

Evertjan.

In an if statement with "document.images" as it's expression, does it
simply check if there are any image elements in an HTML page? I'm
assuming if it finds any that the expression will return true and
execute the statements within the if.

if(document.images)
{
// various statements....
}

No, not true, try:

<script type='text/javascript'>

if (document.images) alert(document.images);

</script>

This returns [object] even if there are no img elemants.

(document.images) only equates to false if the object is not part of the
DOM of that browser, or if no DOM exists [in a non browser environment,
methinks].
 
L

Lee

(e-mail address removed) said:
In an if statement with "document.images" as it's expression, does it
simply check if there are any image elements in an HTML page? I'm
assuming if it finds any that the expression will return true and
execute the statements within the if.

if(document.images)
{
// various statements....
}

No, there don't have to be any images on the page for document.images
to evaluate to true. The browser simply has to support images (and in
some cases, images may have to be enabled).


--
 
T

Tom Cole

(e-mail address removed) said:





No, there don't have to be any images on the page for document.images
to evaluate to true. The browser simply has to support images (and in
some cases, images may have to be enabled).

--

You can call document.images.length and if it returns 0 then there are
no images, if it returns >= 1 then there are.

if (document.images.length > 0) {
//do image stuff
}
else {
//do no image stuff
}
 
U

Une Bévue

Tom Cole said:
You can call document.images.length and if it returns 0 then there are
no images, if it returns >= 1 then there are.

Are you sure about that ?

Because i thought in case images are only included by css, ie. :

myTag {background-image: url(<URL of an image>;}

that kind of image isn't seen by document.images ???
 
T

Tom Cole

Are you sure about that ?

Because i thought in case images are only included by css, ie. :

myTag {background-image: url(<URL of an image>;}

that kind of image isn't seen by document.images ???

Maybe I'm weird, but I wouldn't expect them to. I would expect to get
a array of <img> tags...the same as calling
document.getElementsByTagName('IMG').

I was unaware that the OP was looking for something different. He said
he was looking for image elements....
 
P

Patient Guy

In an if statement with "document.images" as it's expression, does it
simply check if there are any image elements in an HTML page? I'm
assuming if it finds any that the expression will return true and
execute the statements within the if.

if(document.images)
{
// various statements....
}

Since the 'images' property is an array ("collection"?), I would guess that
if you really wanted to find a condition in which there are images truly in
the document, why not evaluate: if (document.images.length > 0)
 

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

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top