Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / March 2007



Tip: Looking for answers? Try searching our database.

About the DOM document object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Draenox@gmail.com - 29 Mar 2007 21:39 GMT
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....
}
Evertjan. - 29 Mar 2007 21:48 GMT
Draenox@gmail.com wrote on 29 mrt 2007 in comp.lang.javascript:

> 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
[quoted text clipped - 5 lines]
>      // 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].

Signature

Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Lee - 29 Mar 2007 21:49 GMT
Draenox@gmail.com 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
[quoted text clipped - 5 lines]
>     // 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).

--
Tom Cole - 30 Mar 2007 14:21 GMT
> Drae...@gmail.com said:
>
[quoted text clipped - 13 lines]
>
> --

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
}
Une Bév ue - 30 Mar 2007 15:11 GMT
> 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 ???
Signature

Une Bévue

Tom Cole - 30 Mar 2007 16:41 GMT
On Mar 30, 9:11 am, unbewusst.s...@wortanschahung.com.invalid (Une
Bévue) wrote:

> > You can call document.images.length and if it returns 0 then there are
> > no images, if it returns >= 1 then there are.
[quoted text clipped - 8 lines]
> --
> Une Bévue

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....
Randy Webb - 30 Mar 2007 19:02 GMT
Tom Cole said the following on 3/30/2007 11:41 AM:
> On Mar 30, 9:11 am, unbewusst.s...@wortanschahung.com.invalid (Une
> Bévue) wrote:
[quoted text clipped - 12 lines]
>
> Maybe I'm weird, but I wouldn't expect them to.

It doesn't.

> I would expect to get a array of <img> tags...the same as calling
> document.getElementsByTagName('IMG').

Pretty much what it gives when you do something like:

allImages = document.images;

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

No, he was asking for clarification of what the posted code did.

Signature

Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Patient Guy - 31 Mar 2007 09:22 GMT
"Draenox@gmail.com" <Draenox@gmail.com> wrote in comp.lang.javascript:

> 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
[quoted text clipped - 5 lines]
>      // 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)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.