Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document.images is empty

Status
Not open for further replies.

kettch

Programmer
Mar 5, 2001
110
US
Is there any circumstances where the document.images collection would be empty, even though there are images on the page?

Here is the HTML:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html dir="ltr" xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

<title>Untitled 1</title>

<link href="Styles/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="img.js"></script>
</head>

<body>
<div class="Header" >
<img alt="Practice Management Services Inc." src="Images/LogoHeader.jpg" /></div>
<div class="NavBar">
	<img src="Images/Buttons/Home.jpg"><img src="Images/Buttons/Clients.jpg" /></div>
<!-- #BeginEditable "body" -->
<div></div>
</body>
</html>

And here is the JavaScript that I have so far in img.js:

Code:
var imgCount =  document.images.length;

For some reason this keeps telling me that the array is empty. Admittedly, I've never used this collection before, so I don't know how it works, but I can't find any documentation that says this can't be used this way.

Thanks for any help.
 
Hi

When that code is executed there are no images yet.
Code:
[b]var[/b] imgCount
window[teal].[/teal]onload[teal]=[/teal][b]function[/b][teal]()[/teal] [teal]{[/teal]
  imgCount [teal]=[/teal]  document[teal].[/teal]images[teal].[/teal]length[teal];[/teal]
[teal]}[/teal]
Or just move the [tt]script[/tt] tag immediately before the closing [tt]body[/tt] tag.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top