473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

About the DOM document object

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

Mar 29 '07 #1
7 1264
Dr*****@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
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].
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 29 '07 #2
Lee
Dr*****@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
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).
--

Mar 29 '07 #3
On Mar 29, 3:49 pm, Lee <REM0VElbspamt...@cox.netwrote:
Drae...@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
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).

--
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
}

Mar 30 '07 #4
Tom Cole <tc****@gmail.comwrote:
>
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 ???
--
Une Bévue
Mar 30 '07 #5
On Mar 30, 9:11 am, unbewusst.s...@wortanschahung.com.invalid (Une
Bévue) wrote:
Tom Cole <tco...@gmail.comwrote:
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 ???
--
Une Bévue
Maybe I'm weird, but I wouldn't expect them to. I would expect to get
a array of <imgtags...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....

Mar 30 '07 #6
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:
>Tom Cole <tco...@gmail.comwrote:
>>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 ???
--
Une Bévue

Maybe I'm weird, but I wouldn't expect them to.
It doesn't.
I would expect to get a array of <imgtags...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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 30 '07 #7
"Dr*****@gmail.com" <Dr*****@gmail.comwrote 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
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)
Mar 31 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Aaron | last post by:
Hi, I've seen javascript code where a constructor function is passed an argument "document", and inside the function itself the assignment "this.document = document;" is made. This is the code...
4
by: Wow | last post by:
when calling a object in an html, should I use self.objectname this.objectname or document.objectname? for example, i have a form called theform and a link called thelink i can call...
6
by: John Salerno | last post by:
I have a question about how one of these methods is called. The call theNote.Write(); uses the Write() method in the Document class, and not the Write() from the Note class. Why is this?...
2
by: Gabriel Lozano-Morán | last post by:
Assume that you have a Document class that you want to persist. Which solution would be better and what are the advantages/disadvantages of each approach? Document doc = new Document(); 1)...
13
by: usenet | last post by:
How and where can one find out about the basics of VB/Access2003 syntax? I am a died in the wool C/C++/Java Linux/Unix programmer and I am finding it difficult to understand the program format...
2
by: chris.dannemiller | last post by:
1. I have a MDI document what is the best way to link data form a specific MDI document to parameters of a property grid. In this case I have a palette that can change from document to document,...
5
by: -Lost | last post by:
Error: uncaught exception: " nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)" location: "JS frame :: file:///D:/sites/_test/js/iterate_document.htm :: <TOP_LEVEL:: line 15" data: no] Line 15...
2
by: Oltmans | last post by:
Hi all, I'm stuck in a situation where I need help. Any help will be highly appreciated. I've created an object, after creating the object, I'm assigning one of its functions to an event handler...
20
by: Aaron Gray | last post by:
There does not seem too be anyway to test if two jQuery references are the same element. Given :- ... <div id="1"></div .... Then :- alert( $("#1") == $("#1"))
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.