Jump to content

Style Undefined Error


Welcome

Recommended Posts

When I try to style an image's cursor I get an undefined error. Here is the line of code causing the problem:

document.images.style.cursor="pointer"

I checked the cursor property to make sure I hadn't made a syntax error. But, according to the cursor propterty page ( http://www.w3schools.com/htmldom/prop_style_cursor.asp ) my syntax is correct (object.style.cursor="cursor"). In Firefox I get this error: "document.images.style is undefined." This works if I use "this.style.cursor='cursor'" inline, but not how I'm trying to do it. Here is the full code I'm using:

	<script type="text/javascript">			var x;		for (x in document.images)		{			document.images.style.cursor="pointer";		}			</script>

In case you haven't realized the script is supposed to find all images and style the cursor. By the way, the script is in the body section. What am I doing wrong?

Link to comment
Share on other sites

What you are doing is you are assigning each individual image to x, but then trying to apply the style to document.images without using x.Really, though, document.images is deprecated - document.getElementsByTagName is better.

var images = document.getElementsByTagName("img");for (i = 0; i < images.length; i++) {	images[i].style.cursor = "pointer";}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...